如题,存储过程返回了多个结果集,
我想把其中一个结果集(可以放入一个临时表),请问如何解决呢?不要用C#代码,需要用在sql studio 里执行。谢谢

解决方案 »

  1.   

    create table #t(col type,...)insert #t exec proc_name 'ref',...select * from #t
      

  2.   

    create procedure test1
    as 
    begin
    select * from a
    select * from b
    endthis will return two result set.how can i get the second result set.if below procedure store , i know how to docreate procedure test2
    as 
    begin
    select * from a
    endinsert into #Tem execute test2use this i can get the result set.
      

  3.   

    这种情况tsql没有直接的方法,一般需要变通处理
    针对存储过程
    create procedure test1 
    as 
    begin 
    select * from a 
    select * from b 
    end 
    1)如果表a和表b结构一致,他们的返回结果集应该合并了,是能取到完整数据
    2)如果表a和表b结构不一致,那么将其中一个表返回到实体表或者全局临时表中去如下:
    create procedure test1 
    as 
    begin 
    select * from a 
    select * into ##b from b 
    end --获取结果集
    declare @a table(....)
    insert into @a exec test1select * from @a
    select * from ##b
    --删除全局临时表
    drop table ##b
      

  4.   

    insert into a as select * from b