Вниз
Скачать: 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.006 c
15-1277585052
AKE
2010-06-27 00:44
2010.09.19
Как звали французского шахматиста конца 18 века?


2-1277184150
Seally
2010-06-22 09:22
2010.09.19
проблема с AdvStringGrid 2.0 в delphi 5


2-1277316263
ribos
2010-06-23 22:04
2010.09.19
В консоли ошибок нет, переношу под VCL вылетает исключение


15-1277096188
tipman
2010-06-21 08:56
2010.09.19
Выпадающая таблица или таблица в ComboBox


3-1245398109
Patrick
2009-06-19 11:55
2010.09.19
Группировка данных при использовании ExpressQuantumGrid




   Наверх