There is no such elegant solution to this type of problem, although this seems to be a common occurrence. Everything between begin transaction and commit or rollback is complete. You cannot just insert a row into the log table, for example, and save it after a possible rollback .
But you can do some tricks.
1) Call your procedure with xp_cmdshell to call OSQL.exe. Performance will be poor, but external commands are not involved in the transaction, and nothing prevents you from executing external SQL queries.
2) in the stored procedure, you can add entries to the variable table instead of the real table. Table variables do not participate in the transaction because they do not modify the database. After that, add the contents of the variable to your table when you closed the transaction anyway.
3) If you cannot change the internal procedure, you can extract the records (records) that it may have created into the table variable after , but from within an open transaction. Rollback the transaction and add the extracted records to the table again.
source share