I am trying to get a query that can help me achieve something similar to the image below:
The first table is the result of a SQL OUTPUT clause (both inserted and deleted). I would like to split these results into a new table (like the second one in the above image). So I want to have one row depicting the inserted records and the second row depicting the deleted records.
This is how my sample data was created:
select
inserted_ID = 1,
inserted_name = 'Brian',
inserted_phone = '123-456-7890',
operation_type1 = 'inserted',
deleted_id = 2,
deleted_name = 'James',
deleted_phone = '222-222-2222',
operation_type2 = 'Deleted'
into
#tbltest

Inserted_IDandDeleted_IDon the same row. Is there any actual / natural relationship between those two?OUTPUTclause allows access to bothinsertedanddeletedrecords during anUPDATEstatement, which is exactly what I stated in my answer. BUT, even if you access bothinsertedanddeletedvalues, per each row coming out ofOUTPUT,insertedanddeletedrepresent the same row:insertedis the "current" value of each column, and `deleted" is the "old" value of each column. But they will never be different rows. Hence this separation that you are asking for only makes sense if wanting "before" and "after" versions of a row to be in diff rows in your table.