Output to Temporary Table in SQL Server 2005

纵饮孤独 提交于 2019-12-01 03:17:16

问题


I am trying to use the OUTPUT clause inside a stored procedure to output to a temporary table the values of an indentity column after an INSERT.

CREATE TABLE #Test
(
    ID INT
)

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

However, when I execute this procedure SQL Server shows me the results in a table (correctly) called Test but if I write SELECT * FROM #Test as the next statement in the stored procedure it shows me nothing. How can I efectively accomplish this?


回答1:


I think you're missing an INTO - try this:

CREATE TABLE #Test(ID INT)

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

After the list of columns to OUTPUT, add an INTO before the table name



来源:https://stackoverflow.com/questions/6292154/output-to-temporary-table-in-sql-server-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!