Retrieve data from stored procedure which has multiple result sets

后端 未结 9 562
一个人的身影
一个人的身影 2020-11-30 08:47

Given a stored procedure in SQL Server which has multiple select statements, is there a way to work with those results separately while calling the procedure?

9条回答
  •  醉酒成梦
    2020-11-30 09:26

    Would passing a parameter to the sp do the trick
    ----------------------
    CREATE PROCEDURE  dostuff @parm1 int
    AS
    
    BEGIN
    Declare @resultset Int
    Set @resultset = @parm1
    
    --0 = Select ranks
    --1 = Select suits
    --other - Select ALL
    
    If @resultset = 0 
     SELECT [rank] FROM [ranks]
     Else If @resultset = 1
     SELECT [suit] FROM [suits]
     Else 
     SELECT * FROM [suits]
     cross join   [ranks] 
    END
    GO
    
     declare @mytemptbl table (rank text)
     insert @mytemptbl
      exec dostuff 0
    
     select * from @mytemptbl
    

提交回复
热议问题