within a trigger, there is a couple of functions you can use you can use to determine if a column has changed:
IF (UPDATE(columnname) ) returns true or false, if you are testing a single column, so you could do something like this:
CREATE TRIGGER TR_WHATEVER
ON WHATEVER
FOR INSERT,UPDATE
AS
IF (UPDATE(DESCRIP) )
BEGIN
INSERT INTO AUDIT(WHATEVERID,NEWVAL,OLDVAL,UPDATEDDT)
SELECT INSERTED.WHATEVERID,
INSERTED.DESCRIP AS NEWVAL,
DELETED.DESCRIP AS OLDVAL,
GETDATE() AS UPDATEDDT
FROM INSERTED
INNER JOIN DELETED
ON INSERTED.WHATEVERID=DELETED.WHATEVERID
END
the other function, COLUMNS_UPDATED, uses a bitmask, and references columns by their ordinal position...NOT by name, to determine whether the columns have had changes:
/*Check whether columns 2 thru 8 have been updated.
for example ,If any or all
columns 2, 3 or 4 have been changed, create an audit record. The
bitmask is: power(2,(2-1))+power(2,(3-1))+power(2,(4-1)) = 14. To test
whether all columns 2, 3, and 4 are updated, use = 14 instead of > 0
(below).
this one specifically is for 32 thru 8 is:
select power(2,(3-1))
+ power(2,(4-1))
+ power(2,(5-1))
+ power(2,(6-1))
+ power(2,(7-1))
+ power(2,(8-1)) = 252*/
IF (substring(COLUMNS_UPDATED(),1,1) & 252 )>0
--do stuff
Lowell