Temporary table output in SQL Server 2005

I am trying to use a clause OUTPUTinside a stored procedure to output indentation column values ​​to a temporary table after INSERT.

CREATE TABLE #Test
(
    ID INT
)

INSERT INTO [TableB] OUTPUT INSERTED.ID #Test SELECT * FROM [TableA]

However, when I perform this procedure, SQL Server shows me the results in the table (correctly) under the name Test, but if I write SELECT * FROM #Testas the next statement in the stored procedure, it will not show me anything. How can I do this efficiently?

+3
source share
1 answer

I think you are missing INTO- try the following:

CREATE TABLE #Test(ID INT)

INSERT INTO [TableB] 
    OUTPUT INSERTED.ID INTO #Test 
    SELECT * FROM [TableA]

After the list of columns in OUTPUTadd INTObefore the table name

+10
source

All Articles