T-SQL Add the INTO clause for the OUTPUT clause
Budget: $10 – $30 USD
We just want to show the inserted and deleted record in the COMMIT TRANSACTION errors so we can compare the errors for duplicate keys values easier. Add something to the OUTPUT clause so the transaction will execute and show the errors. This is for a Transaction with 50 tables so I don't want to have to create 50 temp tables. It could be that adding a string will work. Test database attached. You would need to add some triggers to re-create the error.
SELECT '' 'table1', * FROM [MergeAccounts].[dbo].[table1]
begin transaction
UPDATE [dbo].[table1]
SET [IDNUM] = 11111
OUTPUT '' ins, inserted.*, '' del, deleted.*
--OUTPUT '' ins, inserted.*, '' del, deleted.* INTO @string--The target table of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. Add INTO something.
WHERE IDNUM = 11113
--commit transaction
select @@error Error
If @@error = 0
COMMIT TRANSACTION
Else
ROLLBACK TRANSACTION
;
SELECT '' 'table1', * FROM [MergeAccounts].[dbo].[table1]
SELECT '' 'table1', * FROM [MergeAccounts].[dbo].[table1]
begin transaction
UPDATE [dbo].[table1]
SET [IDNUM] = 11111
OUTPUT '' ins, inserted.*, '' del, deleted.*
--OUTPUT '' ins, inserted.*, '' del, deleted.* INTO @string--The target table of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. Add INTO something.
WHERE IDNUM = 11113
--commit transaction
select @@error Error
If @@error = 0
COMMIT TRANSACTION
Else
ROLLBACK TRANSACTION
;
SELECT '' 'table1', * FROM [MergeAccounts].[dbo].[table1]
Related categories:
Database Programming
Microsoft SQL Server
T-SQL (Transact Structures Query Language)