DECLARE @Temp TABLE (col_1 INT, col_2 INT, col_3 INT, col_4 INT)
INSERT INTO table_1(col_1, col_2, col_3)
OUTPUT INSERTED.val_1, INSERTED.val_2, INSERTED.val_2, INSERTED.val_3, tab.val_4 INTO @Temp(col_1, col_2, col_3, col_4)
SELECT tab.val_1,
tab.val_2,
tab.val_3
FROM table_2 AS tab
WHERE tab.something > 0
I need to insert values from table_2 to table_1 and @Temp table. The problem is table_1 doestn't have a column which is available in @Temp and I couldn't use find a way to use OUTPUT clause which should also use data from the SELECT clause used in table_2.
When I try the above code I get an error,
The multi-part identifier "tab.val_4" could not be bound