在存储过程中嵌套存储过程,语句的书写方法?

sanduVB 2007-10-17 05:12:32
以下的语句的书写,总报错有问题,请问应怎么改进下面的语句。(因存储过程执行结果字段不固定,故无法先建临时表再插入)
select * into #t from Openrowset('sqloledb','Trusted_connection=yes','exec OTERP_JT.dbo.AccAssetsDisPosal @code,@tmonth')
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanduVB 2007-10-18
  • 打赏
  • 举报
回复
create proc TestCom
as
set nocount on
declare @code varchar(20),@tmonth varchar(10)
set @code='A6537'
set @tmonth=10
exec
(
'select * into #t from Openrowset(''sqloledb'',''Trusted_connection=yes'',''exec ZWQ_RR.dbo.AccAssetsDisPosal '''''+@code+''''','''''+@tmonth+''''''')'

)
select * from #t
drop table #t

然后我在查询分析器中执行这个存储过程:
exec TestCom
报错:
“Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS
options to be set for the connection. This ensures consistent query semantics.
Enable these options and then reissue your query.”
plsandslp 2007-10-18
  • 打赏
  • 举报
回复
你看一下是存储过程内部报的错误还是查询语句报的错误,可能是参数的问题
sanduVB 2007-10-18
  • 打赏
  • 举报
回复
我按昨认夜小楼的语句写了。执行语句的时侯报错:
“Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS
options to be set for the connection. This ensures consistent query semantics.
Enable these options and then reissue your query.”

cxmcxm 2007-10-17
  • 打赏
  • 举报
回复
参数不能直接被调用,必须被动态转为字符串
Limpire 2007-10-17
  • 打赏
  • 举报
回复
--将逻辑全部写在一个EXEC里面
declare @code varchar(20),@tmonth varchar(10)
set @code=??
set @tmonth=??
exec
(
'select * into #t from Openrowset(''sqloledb'',''Trusted_connection=yes'',''exec OTERP_JT.dbo.AccAssetsDisPosal '''''+@code+''''','''''+@tmonth+''''''')'
--其它处理逻辑
)
Limpire 2007-10-17
  • 打赏
  • 举报
回复
openrowset不支持动态参数,想其它办法。
sanduVB 2007-10-17
  • 打赏
  • 举报
回复
以上的语句放在存储过程中,报错,+ 附近有错误。
plsandslp 2007-10-17
  • 打赏
  • 举报
回复
select * into #t from
Openrowset( 'sqloledb ', 'Trusted_connection=yes ', 'exec OTERP_JT.dbo.AccAssetsDisPosal '+@code+','+@tmonth +')

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧