|
Answer» I need to create a Trigger for when a ROW is updated to automatically SET the UPDATER and udate_date to the current user and the current date respectively, but I am having trouble doing this. The following is what I currently have:
Code: [Select]CREATE TRIGGER update_projects ON PROJECTS FOR update AS UPDATE projects SET updater = SUBSTRING(SUSER_NAME(), 5, LEN(SUSER_NAME()) - 4), udate_date = GETDATE() WHERE projects.id_num = inserted.id_num But SQL Server tells me:
Msg 4104, Level 16, State 1, Procedure update_projects, Line 5 The multi-part identifier "inserted.id_num" could not be bound.
How can I make this trigger work properly?Problem solved. I really HATE SQL.
Code: [Select]CREATE TRIGGER update_projects ON projects AFTER update AS IF NOT UPDATE(updater) OR NOT UPDATE(update_date) UPDATE projects SET updater = SUBSTRING(SUSER_NAME(), 5, LEN(SUSER_NAME()) - 4), update_date = GETDATE() WHERE id_num IN (SELECT id_num FROM inserted)
|