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 |
superblades
Starting Member
7 Posts |
Posted - 2007-01-03 : 07:27:07
|
Hi Again,im wondering if its possible to copy an old value to another table for audit purposes when its changed. e.g. under tbl_reqs there is a field called fldstatuswhen this field is changed i want it to copy what the field was before and insert it into my tbl_oldstatus table as well as the date it was entered and the corresponsing record number. e.g. before:-tbl_reqsreqnumber - status 123456 - orderedafter:-reqnumber - status123456 - completedtbloldstatusreqnumber - old status - change date123456 - ordered - 03/01/2007etc.Once again i havent got a clue how to do this as im still a newbie! any help is most appreciatedRegardsBrendan Tate |
|
Kristen
Test
22859 Posts |
|
superblades
Starting Member
7 Posts |
Posted - 2007-01-03 : 10:24:04
|
Thanks Kristen ive had a look at the code you have created on that FAQ site but i dont understand what it does ive already got the old status table made, what syntax etc would i need in the trigger? Sorry :)Brendan |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-01-03 : 13:44:37
|
Just to be sure we're on the right wavelength the relevant code you need is here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=170215This will insert into your Audit Table the original values from all the columns in the source table - plus two additional leading columns for the Type of the action (Update or Delete) and the current Date/Time. You can change the SELECT list to only insert the columns you need.If that isn't clear then I reckon you need to read up on Triggers and possibly some more basic syntax stuff on INSERT.Kristen |
|
|
|
|
|