I am using a cursor to loop through a dataset, and for each record in it I want to do an insert or update on a target table. (I run a stored procedure on each record).
If there's an error (e.g., foreign key clash, datatype, etc.) I want to log error info to another table.
I want to keep going through the entire dataset so that I can get any and all errors into the log, BUT when it's all done (and here's the puzzle) if there were ANY errors I want to rollback ALL the inserts/updates on the target table while KEEPING the error information in my log table.
So essentially I want to do series of DML operations on two tables, with the ability to rollback ALL the changes on one, and commit all the changes to the other.
Any ideas on how to accomplish this?
Thanks,