How do i populate the column colNEW in table #tt with the value from column col5 table @t2 in my INSERT statement ? Can my current expression be reused, or do i have to use merge ?
I am using mssql server 10.
DECLARE @t1 TABLE (id INT IDENTITY(1,1), col1 INT, col2 INT)
DECLARE @t2 TABLE (col3 INT, col4 INT, col5 INT)
INSERT @t2 VALUES (1,2,3);INSERT @t2 VALUES (2,3,4)
CREATE TABLE #tt (id INT, col3 INT, col4 INT, colNEW int)
INSERT #tt (id, col3, col4)
SELECT *
FROM
(
INSERT INTO @t1(col1,col2)
OUTPUT Inserted.id, Inserted.col1,Inserted.col2
SELECT col3, col4
FROM @t2
) t
I hope someone can help.