目前,我正试图在Server中执行update (但可能是任何支持子句的DML语句 ),我希望将输出放入本地临时表中,如下所示:
update
dbo.MyTable
set
MyField = 30
output
inserted.MyKeyField
into
#myTempTable
from
dbo.MyTable as t
where
f.MyFilteredField = 8 我知道语法是正确的,根据output子句的文档(强调我的):
output_table 指定将返回的行插入其中而不是返回给调用方的表。output_table可能是临时表。
也就是说,我希望它能像在select语句上的select语句上那样工作,因为它只是创建表。
但是,我得到以下错误:
无效的对象名“#myTempTable”。
如何将output子句(inserted或deleted)的结果输入临时表?
发布于 2012-05-31 18:18:04
output子句不会生成新表,因此您必须使用子句,例如:
select t.MyKeyField into #myTempTable from dbo.MyTable as t where 1 = 0注意,您不必使用上面的select into语法,create table也一样工作。最后,只要最容易创建一个与output子句中的字段相匹配的空临时表。
一旦创建了表,“无效对象名”错误就会消失,DML语句将在没有错误的情况下执行(假设没有其他错误)。
https://stackoverflow.com/questions/10839032
复制相似问题