Question

The issue I'm facing is that I have a stored procedure (lets call it sp_one), which during it's run calls another stored procedure (lets call it sp_two).

I'd only like the resultset from sp_one to be returned at the end, and not those from sp_two. I imagine there is a way to capture the results from sp_two that will prevent them from also being returned but haven't been able to figure the syntax for this.

Any ideas?

Some pseudo code which captures the essence of what is going on (not my actual code):

CREATE PROCEDURE sp_two AS 
BEGIN
  update Users
  set is_valid = 0

  select * from Users
END


CREATE PROCEDURE sp_one
AS
BEGIN
  exec sp_two
  select * from Users
END

exec sp_one

The result of running exec sp_one is the resultset from sp_two, then the results from sp_one. (eg. the users table twice).

Was it helpful?

Solution

In sp_one, you can use

CREATE TABLE #temporaryusers (Usertable fields here)
INSERT INTO #temporaryusers 
EXEC sp_two 

DROP TABLE #temporaryusers 

to swallow your results.

OTHER TIPS

First of all, here is a similiar question

I don't recommand to use this kind of solution, because it could be a bottleneck easily. I would say you should focus on to make the dataprocessing on a much clearer way (however I understand that your question's example is just a theoretical example)

But if you really want to use something like this I would say measure the danger of the returning rows:

1: How many rows returns?

2: How wide is the returning set?

And if you think "ok it is not a big deal", then I would say use a memory table instead of temp table (do not make physical writes):

DECLARE @users TABLE (...fields here...)
INSERT INTO @users
EXEC sp_two 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top