Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-03 : 08:36:52
|
| James writes "Hi, I am new to application development so please don't laugh if the solution to my question is simple. I need to insert rows into an audit table based on what fields have changed on an update.Each row in the Audit table has the following columns:IDOldValueNewValueDateTimeModifiedUserIDI only want to insert a row if a value has changed from the current version of the record. So for example a form might have:Request NameRequest FormatRequest DateClient NameClient LocationClient PhoneIf only one of these fields is updated I only need to insert one row. If they are all updated I need to insert a row for each one.I am aware that the old values and new values are stored in the Inserted and Deleted tables but I'm unsure how to compare the actual columns from these rows. I dont want the solution to be overly messy. I did search the site for information but was unable to locate any suggestions. Any help you could provide would be much appreciated.Kind Regards,James" |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-09-03 : 08:55:11
|
| Check out BOL section CREATE TRIGGER. It explains the use of "IF UPDATE(column_name)" so that in your case you could have something like this:IF UPDATE([Request Name]) INSERT INTO audit_tabele ....And repeat that for each column you are interested in.Raymond |
 |
|
|
|
|
|