Saved by ta_audit_trail

I made a typo in an update statement in our live environment this morning.  It could have been a long day to fix it, as I blanked out a field in tx_cust_sal.  While looking at the update trigger, I noticed that all changes are logged to ta_audit_trail.  I wrote the script below to "rollback" the changes.  I hope someone else finds this useful.

You'll need to change the datetime and other fields based upon your direct needs, so please don't run this as-is.

update
    tx_cust_sal
set
    esal1_desc = a.old_value   
from
    ta_audit_trail a,
    tx_cust_sal sal
where
    a.customer_no = sal.customer_no
and
    a.table_name = 'tx_cust_sal'
and
    a.date > '2009-09-29 09:00:00'
and
    a.date < '2009-09-29 11:00:00'
and
    a.action = 'updated'
and
    a.column_updated = 'esal1_desc'
and
    a.userid = 'dbo'
and
    a.old_value is not null
and
    a.new_value is null

Parents Reply Children
No Data