Today's question comes from Julian.
I have a table with several fields including updated,year,updatedateas well as other tables. I am trying to create a trigger that fires upon insert and update to the table. What I want it to do is to put the current date and time (getdate()) intoupdatedateandyear(getdate())intoyearand setupdatedto 1.I have tried various ways of doing this using an
UPDATESQL statement but this just updates every record in the table. I have tried to limit the records changed by using aWHERE TABLE.RECORDID = INSERTED.RECORDIDbut this just produces an error aboutinserted.recordidnot existing. I tried anUPDATEstatement on theINSERTEDtable but SQL complains that I can't update theINSERTEDtable.How would I go about doing this? Thanks!
Julian
The problem is likely that you are not referring to the INSERTED table in
your UPDATE Statement. I have found the following code is the simplest,
most straightforward way to approach this:
|
This will work for INSERT or UPDATE
Tom
| Read Other SQL Guru Questions |




