How to use a value from one stored procedure in another?
        Posted  
        
            by RoguePlanetoid
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by RoguePlanetoid
        
        
        
        Published on 2010-06-08T09:53:00Z
        Indexed on 
            2010/06/08
            10:02 UTC
        
        
        Read the original article
        Hit count: 257
        
I have the following statement in a Stored Procedure:
DECLARE @Count INT
EXEC @Count = GetItemCount 123
SELECT @Count
Which calls another stored procedure with the following statement inside:
SELECT COUNT(Item) FROM tblItem WHERE ID = @ID
However when I test the call the EXEC outputs the value correctly but it is not assigned to the @Count Variable correctly. I've seen examples or stored procedures used like this, including here but none had a parameter and a return value used (that I could find). The ID Parameter is passed into the second statement which returns a count value used by the first StoredProcedure - all the info I have read seems to indicate this should work - but it doesn't the @Count value is aways zero, even when the GetItemCount returns always the correct value.
This is in Microsoft SQL Server 2008 if that helps.
© Stack Overflow or respective owner