I have two queries being returned by my sproc. I want to be able to select one of them for one thing, and select the other one in another query.
sp_mysproc has two select statements being returned:
select * from Orders where customerid = @customerid
select * from Customer where customerid = @customerid
How can I execute sp_mysproc to get either of these two queries? Do I need to add to end ‘;1’ or ‘;2’?
You should really use two separate stored procs as Martin suggested.
trying to use one function/stored proc to do two different things is just making life more difficult than it has to be.
but if you really want to, and please don’t, take a look at passing in a parameter to tell which query your want and using an if statement to select the appropriate query.
but seriously, please just break it up into two stored procs. I’ve seen plenty of devs try to do this and it just ends up making life for them more complicated later on down the road.
Here would be quick and dirty example of using if statements to select the individual queries…