I have a Stored Procedure that runs and needs to return data as a rowset. It also needs to use that same data to insert into another table, but I am concerned that effectively running 'two' concurrent SELECT
statement (even within a transaction) will potentially return two different results.
How can I ensure the same data is Inserted and then output correctly?
I believe the answer lies in the OUTPUT
function - I've tried reading documentation and examples, but it doesn't quite seem to make sense for my scenario so wanted to check first before doing something way outside of best practice.
Example Code:
SELECT TOP 1 e.*
FROM dbo.[example_selected_table] e
INSERT INTO dbo.[example_insert_table]
SELECT TOP 1 e.*
FROM dbo.[example_selected_table] e