Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2010.09.19;
Скачать: CL | DM;

Вниз

mssql, опять торможу с триггером   Найти похожие ветки 

 
12 ©   (2010-06-23 17:15) [0]

пишу в триггере
---
 insert into rnrTest    --для проверки
 select
     R.*
 from
     rnrRequest R
     join inserted i on R.IdRequest = i.RequestId
 where i.NoSubscr = 1
 
 update R                --что надо сделать
 set
    R.StatusId = -100
 from
    rnrRequest R
    join inserted i on R.IdRequest = i.RequestId
 where i.NoSubscr = 1

-------

делаем запрос

select
 T.IdRequest, R.StatusId
from
 rnrTest T
 join rnrRequest R on R.IdRequest = T.IdRequest

с результатом
51 0

почему не
51 -100
?


 
12 ©   (2010-06-23 17:51) [1]

весь триггер

ALTER TRIGGER [dbo].[rnrAlignmentUpdate_TRGR]
  ON  [dbo].[rnrAlignment]
  AFTER UPDATE
AS
BEGIN
IF ( trigger_nestlevel() > 1) Return;
 
if Exists(select inserted.Id from inserted where inserted.Subscr = 1)
 update rnrAlignment
 set  datatime = GetDate()
 where Id in (select inserted.Id from inserted where inserted.Subscr = 1)
if Exists(select inserted.Id from inserted where inserted.Subscr = 0)
 update rnrAlignment
 set  datatime = null
 where Id in (select inserted.Id from inserted where inserted.Subscr = 0)

if Exists(select inserted.Id from inserted where inserted.NoSubscr = 1)
begin
 update rnrAlignment
 set  datatime = GetDate()
 where Id in (select inserted.Id from inserted where inserted.NoSubscr = 1);

--  insert into rnrTest
--  select R.*
--  from rnrRequest R
--       join inserted i on R.IdRequest = i.RequestId
--  where i.NoSubscr = 1
--  
--  update R  
--  set R.StatusId = -100
--  from rnrRequest R
--       join inserted i on R.IdRequest = i.RequestId
--  where i.NoSubscr = 1
end
if Exists(select inserted.Id from inserted where inserted.NoSubscr = 0)
 update rnrAlignment
 set  datatime = null
 where Id in (select inserted.Id from inserted where inserted.NoSubscr = 0)
END


дано
rnrRequest.IdRequest(PK) - rnrAlignment.RequestId(FK)

На словах задача
как только A.NoSubscr = 1, сразу A.DataTime = getdate
а R.StatusId приравнять к -100 (неполучается именно это)



Страницы: 1 вся ветка

Текущий архив: 2010.09.19;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.011 c
15-1277152197
Юрий
2010-06-22 00:29
2010.09.19
С днем рождения ! 22 июня 2010 вторник


15-1277584193
Юрий
2010-06-27 00:29
2010.09.19
С днем рождения ! 27 июня 2010 воскресенье


15-1277349628
ixen
2010-06-24 07:20
2010.09.19
Не запускается программа. В чем может быть причина?


2-1277491678
New555
2010-06-25 22:47
2010.09.19
if Key = VK_F1 then


2-1277572345
New555
2010-06-26 21:12
2010.09.19
Использовние sndPlaySound для проигрывания нескольких файлов