views:

515

answers:

2

I've got a stored procedure (we'll call it A) that calls another stored procedure (we'll call this one B). B includes a SELECT that I do not want to send back to the caller of A.

Here is some really rough pseudocode, but it should get the idea across.

PROCEDURE A
    CURSOR
        CALL B -- I WANT TO SUPPRESS THE RESULTS FROM B
    END
    SELECT *
END
PROCEDURE B
    Do some interesting things
    SELECT *
END

As you can see above, A calls B and B does some things that I want and returns results that I don't care about. Once A is done, it returns it's own set of results.

How do I suppress the results from B in A? I'm using SQL Server 2005. I would prefer not to make changes to B because it is working and more complex than I want to mess with.

+10  A: 

You can try something like this:

/* Assume this table matches the output of your procedure */
DECLARE @tmpNewValue TABLE (newvalue int)
INSERT INTO @tmpNewValue 
EXEC ProcedureB
JoshBerke
That worked. Thanks.
Brian
My pleasure glad to help
JoshBerke
That's a great solution. But it still causes overhead, doesn't it? I think there should have been an option like `SET NORESULTSETS ON`. I almost always call an SP just for its side effects and I'm not interested in the output of it.
ercan
A: 

Am I being really really stoopid but shouldn't "Do some interesting things" be in another procedure? Then Procedure A would call procedure C (which only does "Do some interesting things") and then do its required select and Procedure B could also call procedure C and do its select, rather than having the overhead of a second select and a temporary table that is only used as a dustbin?

Jim Birchall
OP "would prefer not to make changes to B"
bdukes
+1, Best practices shouldn't get a down vote.
Chris