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.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shankar MPosted Nov 26, 2012, 6:03 AM
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
Krishna GaradPosted Nov 26, 2012, 5:57 AM
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.