문제

this is my trigger in sql server. I want this trigger to fire automatically( i.e daily) instead of update...

create trigger  trig_name
on tab_name
for update
as 
begin
declare   @id int,@innn int
declare @dif int
declare   @inn int
set @id=(select whateverid from inserted)
set @inn = (select DATEDIFF(DAY,INSERTDT,UPDATEDDT) from tab_name where whateverid=@id)
set @innn =(select DATEDIFF(DAY,INSERTDT,GETDATE()) from tab_name where whateverid=@id)
set @dif = @inn-@innn
 update tab_name set due=@dif from tab_name where whateverid= @id
end

올바른 솔루션이 없습니다

다른 팁

Create a new SQL Agent Job, and add a Transact SQL step:

update tab_name 
set due = DATEDIFF(DAY, INSERTDT, UPDATEDDT) - DATEDIFF(DAY, INSERTDT, GETDATE())

Obviously, unlike the trigger, you can't update those that have just been updated. So this will update all 'due' fields based on the time it runs.

I would consider create a stored proc and getting the job to run that instead. It easier manager, and less likely to get missed in the future.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top