Главная страница
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.012 c
15-1277316827
zlodey
2010-06-23 22:13
2010.09.19
песни про программистов


2-1277125693
LDV
2010-06-21 17:08
2010.09.19
проблема с anchor ами


2-1277704401
И. Павел
2010-06-28 09:53
2010.09.19
Общий обработчик ошибок, завершающий программу.


2-1277129198
WHR
2010-06-21 18:06
2010.09.19
Что выбрать: AdoDataSet, ADOQuery, ADOCommand,...?


2-1277368711
LDV
2010-06-24 12:38
2010.09.19
кодировка