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 |
dzirkelb
Yak Posting Veteran
53 Posts |
Posted - 2010-10-07 : 10:48:01
|
I want to create a basic trigger that fires off when the field Appv is changed. When it is changed, I would like to update the field ApprovalDateTime with the current date/time.I have found out how to run an update query when the update happens; however, I do not know how to identify what record specifically to update.How can I tell the trigger what row to update? meaning, how do I find the primary key that was just updated from the trigger? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-10-07 : 11:15:24
|
create trigger dbo.trgMyTriggeron dboMyTableafter updateasset nocount onif update(appv) update t set t.ApprovalDateTime = GETDATE()from dbo.Mytable AS tinner join inserted as i on i.PrimaryKeyColumnNameHere = t.PrimaryKeyColumnNameHerewhere t.ApprovalDateTime is nullgo N 56°04'39.26"E 12°55'05.63" |
|
|
dzirkelb
Yak Posting Veteran
53 Posts |
Posted - 2010-10-07 : 11:55:07
|
Worked like a charm, thanks! |
|
|
|
|
|