Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Get scalar value from EXEC Stored_Procedure

Author  Topic 

mccallug
Starting Member

6 Posts

Posted - 2008-08-14 : 12:35:14
I am creating a recursive stored procedure. I need get the value returned from the stored procedure. I cannot find a way to do this. This is what I have tried so far. My stored procedure only takes one parameter.

DECLARE @TEMP int
SET @TEMP = EXEC Count_Stock_At_Location 1

---Will not run do to incorrect syntax---

Does anyone know how to get scalar value back from EXEC Stored_Procedure?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-14 : 12:44:10
Is the stored procedure returning the value as an OUTPUT parameter, via the RETURN, or in a result set?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-08-14 : 13:41:34
You should lookup the correct syntax for an EXECUTE statement in SQL Server Books Online.

http://msdn.microsoft.com/en-us/library/ms188332(SQL.90).aspx


CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-14 : 13:53:43
either use OUTPUT parameter approach suggested by Tara or just return value as a resultset and use OPENROWSET to return it like below

SELECT @TEMP = returnfield
FROM OPENROWSET(...,'EXEC Count_Stock_At_Location 1')

for getting the other settings of OPENROWSET refer books online or

http://msdn.microsoft.com/en-us/library/ms190312.aspx
Go to Top of Page
   

- Advertisement -