I have a temp table which has a subset of rows copied from another table and updated. While inserting them back into the original table I want to capture their inserted id with the original id in the temp table.
Unfortunately I am getting an error
The multipart identifier "temp.id" could not be bound.
DECLARE @MappingTable TABLE (
old_id BIGINT,
new_id BIGINT
)
SELECT *
INTO #Table1Temp
WHERE col1 = true;
INSERT INTO dbo.table1 ([col1], [col2], [col3], [col4])
OUTPUT
inserted.id, temp.id
INTO @MappingTable (new_id, old_id)
SELECT [col1], [col2], [col3], [col4]
FROM #Table1Temp temp;