Thumb

Return Values in a Stored Procedure

9/14/2020 7:18:05 AM

Return Values in a Stored Procedure: return is a keyword like output. Return keyword return only one value int but output variable any datatype return. When we initialize the variable and return back the variable then we use the out or output variable but when we direct return the result and store the value execute time then we use the return keyword. Now given bellow the example code:

/*CREATE PROCEDURE*/
CREATE PROCEDURE GetDataByReturn
AS
BEGIN
return(select COUNT(Id) from Salary)
END
/* data with Return keyword*/
Declare @EmpFirstName nvarchar(250)
EXEC  @EmpFirstName=GetDataByReturn
print @EmpFirstName

In this code we return int value by using count function and store the value into ‘@EmpFirstName’ variable and print the value.