Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Suppress the SELECT Output of a Stored Procedure called from another Stored Procedure in SQL Server?

I'm not talking about doing a "SET NOCOUNT OFF". But I have a stored procedure which I use to insert some data into some tables. This procedure creates a xml response string, well let me give you an example:

CREATE PROCEDURE [dbo].[insertSomeData] (@myParam int) AS DECLARE @reply varchar(2048)  ... Do a bunch of inserts/updates...  SET @reply = '<xml><big /><outputs /></xml>' SELECT @reply GO 

So I put together a script which uses this SP a bunch of times, and the xml "output" is getting to be too much (it's crashed my box once already).

Is there a way to suppress or redirect the output generated from this stored procedure? I don't think that modifying this stored procedure is an option.

thanks.


I guess i should clarify. This SP above is being called by a T-SQL Update script that i wrote, to be run through enterprise studio manager, etc.

And it's not the most elegant SQL i've ever written either (some psuedo-sql):

WHILE unprocessedRecordsLeft   BEGIN     SELECT top 1 record from updateTable where Processed = 0     EXEC insertSomeData @param = record_From_UpdateTable   END 

So lets say the UpdateTable has some 50k records in it. That SP gets called 50k times, writing 50k xml strings to the output window. It didn't bring the sql server to a stop, just my client app (sql server management studio).

like image 319
Dave Baghdanov Avatar asked May 15 '09 00:05

Dave Baghdanov


People also ask

How do you suppress in SQL?

How to Suppress the Message. If you want to suppress this message, then you can use the “SET NOCOUNT” statement.

Can stored procedures call other stored procedures?

If the appropriate development situation applies, we can use stored procedures to call other stored procedures and conveniently pass values from one procedure to another procedure.

How do you get the output of a stored procedure in a variable in SQL Server?

You can use the return statement inside a stored procedure to return an integer status code (and only of integer type). By convention a return value of zero is used for success. If no return is explicitly set, then the stored procedure returns zero. You should use the return value for status codes only.


1 Answers

The answer you're looking for is found in a similar SO question by Josh Burke:

-- Assume this table matches the output of your procedure DECLARE @tmpNewValue TABLE ([Id] int, [Name] varchar(50))  INSERT INTO @tmpNewValue    EXEC [ProcedureB]  -- SELECT [Id], [Name] FROM @tmpNewValue 
like image 163
Serj Sagan Avatar answered Sep 22 '22 13:09

Serj Sagan