Friday, August 14, 2009

Stored Procedure Returning and Receiving

If the stored procedure is returning a single value you could define one of the parameters on the stored procedure to be an OUTPUT variable, and then the stored procedure would set the value of the parameter

CREATE PROCEDURE dbo.sp_myoutName @In INT, @Out VARCHAR(100) OUTPUT
AS
BEGIN SELECT @Out = 'Test'
END
GO


And then, you get the output value as follows

DECLARE @OUT VARCHAR(100)
EXEC sp_myoutname 1, @Out OUTPUT
PRINT @Out

No comments: