取得存储过程sp2的返回记录,直接select into到临时表: select * into #t from OPENROWSET(
'SQLOLEDB','SERVER=servername;uid=sa;pwd=123;Database=testdb',
'SET FMTONLY OFF;set nocount on;exec sp2 参数') as a
select * from #t
drop table #t

解决方案 »

  1.   

    pbsql(风云):我想就在当前数据库的存储过程里面使用,如果这样的话,改了密码能不能用了,不用再建立连接,能办到吗?
      

  2.   

    那就创建临时表,结构与sp2返回的结构相同create table #t(...)
    insert into #t exec sp2 参数
    select * from #t
    drop table #t
      

  3.   

    --可以这样写:select * into #t
    from openrowset('sqloledb','Trusted_Connection=yes','SET FMTONLY OFF;set nocount on;exec 库名.dbo.sp2 参数')
      

  4.   

    --或者这样写吧,就不用在调用存储过程中指定库名,当然,连接字符串中就要字符串了select * into #t
    from openrowset('sqloledb','Trusted_Connection=yes;Database=testdb','SET FMTONLY OFF;set nocount on;exec sp2 参数')