Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Trigger Question

Author  Topic 

baze7
Yak Posting Veteran

58 Posts

Posted - 2010-02-26 : 17:11:16
How can I trigger on an update of a field?

If I have a table named Job and a field named complete, how can I trigger if the complete field changes from 0 to 1?

Thanks
Chad

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-02-26 : 18:53:43
[CODE]create trigger tu_MyTable_RisingEdge
on dbo.MyTable
for update
as
if exists(
select *
from MyTable t
inner join deleted d
on d.PrimaryKey = t.PrimaryKey
where d.Complete = 0
and t.Complete = 1
)
begin
<Your code goes here>
end[/CODE]


=======================================
Few things are harder to put up with than the annoyance of a good example. (Mark Twain)
Go to Top of Page
   

- Advertisement -