How can a procedure retrieve multiple results sets from another procedure?

  • I have a stored procedure that calls another stored procedure that returns two record sets. If I retrieve the results into a table variable, I get both result sets in the table with no way to separate them.

    Is there any way to process the two sets separately or will I have to break the called procedure into two separate procedures?

    I went all through BOL and found nothing on this topic.

    Thanks for any help,

    Liz

  • Can you add a parameter for returning one result set or the other to the sp that's being called?

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

  • I need both result sets, but I need a way to separate them in the receiving procedure.

  • sing4you (1/19/2011)


    I need both result sets, but I need a way to separate them in the receiving procedure.

    If there is a reason to return both sets at once (such as performance), then an alternative to distinguish each set is to simply add a column to the result set that designates which set each one is. For instance a column named "SetNo" and only contains a "1" or "2". Does that make sense?

    p.s., The only reason I can think of to return both sets at once is that there is overlap in creating the sets, so it helps performance.

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

  • Yes! That totally makes sense. I just tried it and it worked!!! Thanks 😀

  • You're welcome. 'Glad I could help. 🙂

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply