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


15-1276851347
Kerk
2010-06-18 12:55
2010.09.19
Кто-нибудь сталкивался с nosql-базами?


2-1277281421
worldmen
2010-06-23 12:23
2010.09.19
Очистить все TComboBox на форме


11-1222972796
Rocket
2008-10-02 22:39
2010.09.19
Утечка памяти при динамическом создании форм и UNICODE_CTRLS


2-1277246482
Отшельник
2010-06-23 02:41
2010.09.19
Как узнать, подключена ли другая программа к серверу?