Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Trap Return value of a Stored Procedure

Status
Not open for further replies.

mukund

Programmer
Mar 6, 2001
64
GB
How does one trap the Return value of a stored procedure.

I want to call one stored procedure, that return a Integer value by using the Return Statement.

I want to use this Return value in the calling Stored Procedure.


Mukund.
 
Hi, here it goes, run the script
Code:
/*Calling procedure*/
create  procedure proc1 
as
declare @result int
exec proc2 @result output
print @result
go
/*Another procedure*/
Create procedure proc2 @paramout int output
as
SET @paramout=1
go
exec proc1
Hope this helps
Praveen
 
Thanks for the help Praveen.

But I used the following syntax

EXECUTE @OutAddrId = generateid 'AddrId', @HubId

Here @OutAddrId is the parameter in which the result will be returned.

generateid is the procedure being called with 'AddrId' and @HubId as two parameters.

Mukund.
 
Code:
create procedure usp_generateid @Addrid int,@hubid int
as
/*Do something */
Declare @outaddr int
IF @addriD>@hubid
BEGIN
    SET @outaddr=999
END
ELSE
BEGIN
    SET @outaddr=888
END
/*NOTE THAT U CANNOT RETURN NULL VALUES, ONLY INTEGER VALUES ALLOWED TO BE RETURNED*/ 
RETURN @outaddr /*Return the value using RETURN */
GO

/*Call Procedure*/
DECLARE @hubid int,
        @addrrid int,
        @OutAddrId int 
/*need to declare @OutAddrId this holds the result*/

/*Assign values */
SELECT @addrrid=11,@hubid=9

EXECUTE @OutAddrId = usp_generateid @addrrid,@HubId
PRINT @OutAddrId

Somethings to Note when u use the above method,
1>u can return only one value of integer type
2>Multiple values cannot be return
3>Mainly used for returning status of stored procedures or error codes.

I would be perfer to use the the one i posted before.

Praveen


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top