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 2005 Forums
 Transact-SQL (2005)
 Trigger Syntax

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2007-11-15 : 07:24:23
How do I write a trigger so that when a row is updated or inserted,

If FieldA = True Then FieldB = True
If FieldB = False Then FieldB = False

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-15 : 07:28:10
[code]UPDATE t
SET FieldB = CASE WHEN i.FieldA = 1 THEN 1
WHEN i.FieldB = 0 THEN 0
ELSE i.FieldB
END
FROM TABLE t INNER JOIN inserted i
ON t.pk = i.pk[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -