My question is I have one Stored Procedure in SQL Server that returns counts of a field. I want to store the results of this Stored Procedure in a variable (scalar?) of a different stored procedure.
sp_My_Other_SP: CREATE PROCEDURE [dbo].sp_My_Other_SP @variable int OUTPUT -- The returned count AS BEGIN -- SP SET NOCOUNT ON; SET @SQL = "SELECT COUNT(*) FROM blah" EXEC(@SQL) END -- SP
I currently do it like:
DECLARE @count int EXEC sp_My_Other_SP @count OUTPUT
Then I use it like
IF (@count > 0) BEGIN ... END
However its returning the other Stored Procedure results as well as the main Stored Procedure results which is a problem in my .NET application.
----------- NoColName ----------- 14 ----------- MyCol ----------- abc cde efg
(Above is an attempted representation of the results sets returned)
I would like to know if there is a way to store the results of a Stored Procedure into a variable that doesn't also output it.
Thanks for any help.