下面的例子创建了存储过程，该存储过程列出Northwind数据库中过期的定单。

USE Northwind

GO

CREATE PROC dbo.OverdueOrders

AS

SELECT *

FROM dbo.Orders

WHERE RequiredDate < GETDATE () AND ShippedDate IS Null

GO

以下语句创建一个名为EmployeeCustomer的存储过程，该存储过程向Northwind数据库中的Customers表插入雇员。

USE Northwind

GO

CREATE PROC dbo.EmployeeCustomer

AS

SELECT

UPPER(SUBSTRING(LastName,1,4)+SUBSTRING(FirstName,1,1)),

'Northwind Traders',RTRIM(FirstName)+' '+LastName,

'Employee',Address,City,Region,PostalCode,Country,

(' (206)555-1234'+'x'+Extension),NULL

FROM Employees

下面的例子创建了名为Year to Year Sales的存储过程，该存储过程将返回在两个指定日期间的销售额。

CREATE PROCEDURE dbo.[Yeart to Year Sales]

@BeginningDate DateTime,@EndingDate DateTime

AS

IF @BeginningDate IS NULL OR @EndingDate IS NULL

BEGIN

RAISERROR('NULL value are not allowes',14,1)

RETURN

END

SELECT O.ShippedDate,

O.OrderID,

OS.Subtotal,

DATENAME(yy,ShippedDate) AS Year

FROM ORDERS O INNER JOIN [Order Subtotals] OS

ON O.OrderID=OS.OrderID

WHERE O.ShippedDate BETWEEN @BeginningDate AND @EndingDate

GO