SQL Server Examples:
A Simple Stored Procedure


 

Script

This is a simple stored procedure that updates all records of a table. In this example, we pass an argument to the procedure: the value of a raise that would be applied to all employees throughout the company:

-- creating the store procedure
IF EXISTS (SELECT name 
	   FROM   sysobjects 
	   WHERE  name = N'GiveGeneralRaise' 
	   AND 	  type = 'P')
    DROP PROCEDURE GiveGeneralRaise
GO

CREATE PROCEDURE GiveGeneralRaise 
	@NewRaise SmallMoney
AS
	UPDATE Employees
         SET Salary = Salary + @NewRaise
GO
 

Home Copyright © 2004-2010 FunctionX, Inc.