January 24, 2008 at 4:03 pm
I have a trigger on a table for update where the update may be a record at a time or a mass update. I need to check if one of the columns has changed (not updated). I can't use variables to trap values because with a mass update I leaned my lesson the it only updated the first record. The question is how can I compare it. I tried below but this errors out
if select ltrim(rtrim(inserted.df_sitename)) from inserted <> deleted.df_sitename
begin
It wants me to reference the tables in some type of where clause
January 24, 2008 at 8:37 pm
What is it that you want to do if there a rows that have changed between Inserted and Deleted? Perhaps insert into an audit log?
Then, ya gotta think in sets instead of IF's...
INSERT INTO AuditLog
(PK,OldValue,NewValue,ColumnName)
SELECT PK_Col AS PK,
d.df_SiteName AS OldValue,
i.df_SiteName AS NewValue,
'df_SiteName' AS ColumnName
FROM Inserted i
INNER JOIN Deleted d
ON i.PK_Col = d.PK_Col
AND ISNULL(i.df_SiteName,'') <> ISNULL(d.df_SiteName,'')
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply