Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I suppress the results from a stored procedure from within a stored procedure?

Tags:

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 its 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.

like image 616
Brian Avatar asked Feb 20 '09 23:02

Brian


People also ask

Can you cross apply a stored procedure?

CROSS APPLY does not work for Stored Procedures, as they do not return datasets, just report outputs. Functions return anything, so that's why SQL can only use them when using CROSS APPLY.

How do you suppress in SQL?

Statement. To suppress a rule in a statement, the suppression mark must be suffixed with (STATEMENT) – IGNORE:RULENAME(STATEMENT). The suppression mark can appear anywhere in a comment inside the statement or just following the statement.

Why we use set Nocount on in stored procedure?

SET NOCOUNT ON prevents the sending of DONEINPROC messages to the client for each statement in a stored procedure.

How do you store the result of a stored procedure?

The general solution for persisting a results set from a stored procedure is to store the results set(s) in one or more tables. You can use any of several different types of tables, including regular tables, local temp tables and global temp tables.


1 Answers

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 
like image 160
JoshBerke Avatar answered Oct 16 '22 00:10

JoshBerke