Thursday, 30 January 2014

How to create Stored Procedure in MS SQL Server?

Syntex:
CREATE PROCEDURE [dbo].[sp_GetEmployee]
@EmpId INT,
@EmpName VARCHAR(50),
@DOB DATETIME,
@Error VARCHAR(MAX) OUT
AS
BEGIN
     SELECT a.EmpName, b.DeptName FROM tblEmployee a
          JOIN tblDept b ON b.EmpId=a.EmpId
          ORDER BY a.EmpName DESC

     IF @@error <> 0
          SET @Error = ERROR_MESSAGE()
END
Example:

0 comments:

Post a Comment