I have a trigger that is used for auditing inserted, updated and deleted rows. I am having an issue with acquiring the Old Values and New Values from the trigger. The trigger utilizes a loop to insert all values of any row that has been altered in any way (inserted, updated, deleted). However, my code is not returning the values but instead the column names as the values.
Here is part of my code:
SELECT @COLNAME = NAME
FROM SYSCOLUMNS
WHERE COLID = @FIELD AND
ID = (SELECT ID FROM SYSOBJECTS WHERE NAME = 'FIN_HOTEL_DTL_TYPE')
SELECT @OLDVAL = SUBSTRING(@COLNAME, 2, LEN(@COLNAME)) FROM DELETED
SELECT @NEWVAL = SUBSTRING(@COLNAME, 2, LEN(@COLNAME)) FROM INSERTED
SELECT @MODBY = MODIFIED_BY FROM INSERTED
SELECT @MODDT = MODIFIED_DATETIME FROM INSERTED