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.
| Author |
Topic |
|
raxbat
Yak Posting Veteran
52 Posts |
Posted - 2007-09-26 : 02:38:34
|
| Hello all!I need help from You experts!I need to make an update trigger!For example we have table with fields: Value1,Value2,LastChange.The trigger have to make LastChange=GetDate() if on the update the values of Value1 or Value2 were changed!Help me please!!!!! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-26 : 02:51:27
|
[code]CREATE TRIGGER trgTable1Update ON Table1FOR UPDATEIF UPDATE(Value1) OR UPDATE(Value2) UPDATE t1 SET t1.LastChange = CURRENT_TIMESTAMP FROM Table1 AS t1 INNER JOIN inserted AS i ON i.PkCol = t1.PkCol INNER JOIN deleted AS d ON d.PkCol = t1.PkCol WHERE i.Value1 <> d.Value1 OR i.Value2 <> d.Value2[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
raxbat
Yak Posting Veteran
52 Posts |
Posted - 2007-09-26 : 03:02:46
|
| Thanx a lot! |
 |
|
|
raxbat
Yak Posting Veteran
52 Posts |
Posted - 2007-09-26 : 03:06:26
|
| Script doesnt run beacouse of the following error:"Error 156" incorect syntax near word IF and OR |
 |
|
|
raxbat
Yak Posting Veteran
52 Posts |
Posted - 2007-09-26 : 03:11:51
|
Got it!!! |
 |
|
|
|
|
|