We help IT Professionals succeed at work.

SQL Trigger - update - add date to date field when status field changes to value 2

donhannam asked
Last Modified: 2012-05-11
I want to set up a trigger on a table so that when the status field is changed to 2 (will be from either 0 or 1) that the trigger inserts the date the status was set to 2 in a seperate field say StatusUpdatedDate. I do not want this updated if another field on this record is update so carn't just check the field value = 2 and then update date with getdate.
Would like to read the status of the record before it is updated to compare. I can get the value of the inserted record but not sure how to get the value of the record before updated - I guess SQL deletes and inserts?.
Watch Question

Chief Technology Officer
Most Valuable Expert 2011
This one is on us!
(Get your first solution completely free - no credit card required)


Great thanks - both will work - I think I'll use the delete/insert comparison.
if deleted.status < 2 and inserted.status = 2
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.