Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.007 c
15-1277099793
12
2010-06-21 09:56
2010.09.19
Ошибка AV на строке TRY. Что за ерунда?


15-1277320579
TStas
2010-06-23 23:16
2010.09.19
Можно ли выходить в интернет с двух компов?


2-1277507605
evgenic438
2010-06-26 03:13
2010.09.19
Размеры формы


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


2-1276167910
dimds
2010-06-10 15:05
2010.09.19
Подключение к серверу из среды Delphi




   Наверх