输出到 SQL Server 2005 中的临时表 [英] Output to Temporary Table in SQL Server 2005

查看:30
本文介绍了输出到 SQL Server 2005 中的临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OUTPUT 子句 在存储过程中INSERT.

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]

但是,当我执行此过程时,SQL Server 向我显示了一个名为 Test 的表(正确)中的结果,但是如果我将 SELECT * FROM #Test 写为下一个存储过程中的语句它没有显示任何内容.我怎样才能有效地做到这一点?

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?

推荐答案

我认为您缺少一个 INTO - 试试这个:

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]

在列到OUTPUT的列表之后,在表名前添加一个INTO

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

这篇关于输出到 SQL Server 2005 中的临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆