以下的语句的书写,总报错有问题,请问应怎么改进下面的语句。(因存储过程执行结果字段不固定,故无法先建临时表再插入)
select * into #t from Openrowset('sqloledb','Trusted_connection=yes','exec OTERP_JT.dbo.AccAssetsDisPosal @code,@tmonth')

解决方案 »

  1.   

    select * into #t from 
    Openrowset( 'sqloledb ', 'Trusted_connection=yes ', 'exec OTERP_JT.dbo.AccAssetsDisPosal '+@code+','+@tmonth +')
      

  2.   

    openrowset不支持动态参数,想其它办法。
      

  3.   

    --将逻辑全部写在一个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+''''''')'
    --其它处理逻辑
    )
      

  4.   

    我按昨认夜小楼的语句写了。执行语句的时侯报错:
    “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.”
      

  5.   

    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.”