Executing multiple stored procedure and get one final dataset.

Ali Ahad 131 Reputation points
2023-06-11T17:59:28.1833333+00:00

I have multiple stored procedures that I am running but I need to combine all results into one dataset. For example

exec sp A gives me 15 rows

exec sp B gives me 10 rows

I want to execute both and get 25 rows in my final output.

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2023-06-11T18:16:01.1266667+00:00

    For example:

    drop table if exists #t
    
    create table #t (Col1 int, Col2 varchar(max))
    
    insert #t exec spA
    
    insert #t exec spB
    
    select * from #t
    
    0 comments No comments

  2. LiHongMSFT-4306 31,566 Reputation points
    2023-06-12T01:53:36.71+00:00

    Hi @Ali Ahad

    By the way, if there is no parameter to specify when executing SP, you could generate the scripts to one single script dynamically.

    Best regards,

    Cosmog Hong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.