openrowset给出了错误" OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"已退回的消息"无法完成延期准备。"

时间:2015-07-26 11:01:49

标签: sql-server-2008

我有一个传递给存储过程的表。现在我想在openrow中使用' select * into #b将临时表#b中的存储过程结果插入。我的sql代码如下:

create type add1 as table
(score int)

alter proc qwe123
@table add1 readonly
as
begin
select score,score + 2 as cal
from @table
end

go

declare @t add1 
insert into @t
select score
from abc

select * into #b from
openrowset('sqlncli','server=localhost;trusted_connection=yes','exec qwe123 @t')

有人可以告诉我为什么我会收到错误:

OLE DB提供程序" SQLNCLI10"对于链接服务器"(null)"返回消息"延期准备无法完成。"。

Msg 8180,Level 16,State 1,Line 1

无法准备声明。

Msg 137,Level 15,State 2,Line 1

必须声明标量变量" @ t"。

1 个答案:

答案 0 :(得分:1)

您必须使用执行语句声明变量@t

openrowset('sqlncli','server=localhost;trusted_connection=yes',
    'DECLARE @t add1 = 1 exec qwe123 @t')
相关问题