Create Stored Procedure in SQL
I have a table, in which two column id and salary is defined. I want to create a stored procedure, by which salary is returned on behalf of id.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Krishna GaradRank #191 · 12.8K reputationPosted Nov 26, 2012, 12:57 AM EST
Create Procedure Sp_ReturnSalary
(
@id int,
@salary money out
)
As
Begin
Set@salary=(Select Salary From TableName Where Id=@id)
End
When calling this stored procedure provide parameterdirection to output for salary.
Shankar MRank #874 · 2.5K reputationPosted Nov 26, 2012, 1:03 AM EST
Hi Sharad,
Suppose, if you have column names for Employee Number as EMPNO and Salary and SAL. The Stored Procedure
to Fetch the SAL based on the Input of the Employee Number is,
CREATE PROCEDURE [SP_EMPSAL](@EMPLOYEENO int)
as
DECLARE @SALARY INT
SELECT @SALARY=SAL FROM EMP WHERE EMPNO=@EMPLOYEENO
SELECT @SALARY
The Input Parameter here is @EMPLOYEENO
To Execute the Procedure :
EXEC SP_EMPSAL 8957
Here 8975 is an Employee record found in the EMP Table.
Thanks,
Shankar