[英]Output to Temporary Table in SQL Server 2005
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
.我正在尝试在存储过程中使用OUTPUT
子句到 output 到临时表中INSERT
之后的 indentity 列的值。
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.但是,当我执行此过程 SQL 服务器在名为Test
的表(正确)中向我显示结果时,但如果我将SELECT * FROM #Test
作为存储过程中的下一条语句,它什么也没显示。 How can I efectively accomplish this?我怎样才能有效地做到这一点?
I think you're missing an INTO
- try this:我认为你错过了一个INTO
- 试试这个:
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在OUTPUT
的列列表之后,在表名前添加一个INTO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.