Avatar of cat4larry
cat4larry asked on

Pass the Result Set of One Stored Procedure into a Second Stored Procedure as an Input Parameter

As the title says, I need to pass a result set from a stored procedure into another as an input parameter.  Here's my situation:

I have a VERY LONG stored procedure that in essence is the heart and soul of my application.  It handles one of the most important features of the app.  But yeah, it's very long.  However it can probably be broken down into two main parts:  the part that selects a bunch of data and the part that inserts said data into a bunch of different places.

So I would like to break it apart into 2 stored procedures just to make it a little more palatable for the junior developers who also need to work on it.  

The result set amounts to 3 columns of data.  I've thought about using a more permanent temp table (I believe @@Temps are permanent until explicitly disposed) in which case I wouldn't even have to pass it as an input parameter I would simply need to reference it.

Anyway, I'm open to suggestions.
Microsoft SQL Server

Avatar of undefined
Last Comment
cat4larry

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
cat4larry

For curiosity sake though, how would one pass the result set from one proc into another proc.  Could I use some sort of table variable?

DaveKid
Scott Pletcher

No, table variables don't survive outside their immediate scope.

You really should use either a temporary table or a permanent table with a key to identify the row(s) for the proc called to process.
ASKER
cat4larry

K, Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy