SQL Server/T-SQL Tutorial/Procedure Function/Procedure — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 10:25, 26 мая 2010

calls the procedure

10> create table Billings (
11>     BankerID           INTEGER,
12>     BillingNumber      INTEGER,
13>     BillingDate        datetime,
14>     BillingTotal       INTEGER,
15>     TermsID            INTEGER,
16>     BillingDueDate     datetime ,
17>     PaymentTotal       INTEGER,
18>     CreditTotal        INTEGER
19>
20> );
21> GO
1>
2> INSERT INTO Billings VALUES (1, 1, "2005-01-22", 165, 1,"2005-04-22",123,321);
3> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (2, 2, "2001-02-21", 165, 1,"2002-02-22",123,321.);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (3, 3, "2003-05-02", 165, 1,"2005-04-12",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (4, 4, "1999-03-12", 165, 1,"2005-04-18",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (5, 5, "2000-04-23", 165, 1,"2005-04-17",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (6, 6, "2001-06-14", 165, 1,"2005-04-18",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (7, 7, "2002-07-15", 165, 1,"2005-04-19",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (8, 8, "2003-08-16", 165, 1,"2005-04-20",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (9, 9, "2004-09-17", 165, 1,"2005-04-21",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (0, 0, "2005-10-18", 165, 1,"2005-04-22",123,321);
2> GO
(1 rows affected)
1>
2>
3> CREATE PROC spInsertBilling
4>        @BankerID    int,           @BillingNumber  varchar(50),
5>        @BillingDate smalldatetime, @BillingTotal   money,
6>        @TermsID     int,           @BillingDueDate smalldatetime
7> AS
8> IF EXISTS(SELECT * FROM Billings WHERE BankerID = @BankerID)
9>     BEGIN
10>         INSERT Billings (BankerID)
11>         VALUES (@BankerID)
12>     END
13> ELSE
14>     BEGIN
15>         RAISERROR("Not a valid BankerID!",1,1)
16>         RETURN -100
17>     END
18> GO
1>
2>
3> DECLARE @ReturnVar int
4> EXEC @ReturnVar = spInsertBilling
5>      799,"ZXK-799","2002-07-01",299.95,1,"2001-08-01"
6> PRINT "Return code was: " + CONVERT(varchar,@ReturnVar)
7> GO
Not a valid BankerID!
Return code was: -100
1>
2> drop PROC spInsertBilling;
3> GO
1>
2>
3> drop table Billings;
4> GO
1>


Declare a variable in a procedure

4> CREATE TABLE Product(
5>     ProductID               int                NOT NULL,
6>     Name                    nvarchar(25)       NOT NULL,
7>     ProductNumber           nvarchar(25)               ,
8>      Color                   nvarchar(15)       NULL,
9>      StandardCost            money              NOT NULL,
10>      Size                    nvarchar(5)        NULL,
11>      Weight                  decimal(8, 2)      NULL,
12>      ProductLine             nchar(20)           NULL,
13>      SellStartDate           datetime           NOT NULL,
14>      SellEndDate             datetime           NULL
15>  )
16>  GO
1> insert into Product values(1,"Product A", "1","Red",123.123,"1",1,"ProductLine A","1999-03-22","2000-03-22");
2> GO
(1 rows affected)
1>
2>
3> insert into Product values(2,"Product B", "2","Yellow",234.234,"1",3,"ProductLine B","2000-03-22","2001-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(3,"Product C", "3","Pink",345.345,"1",3,"ProductLine V","2001-09-22","2006-02-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(4,"Product D", "4","White",456.456,"1",4,"ProductLine D","2002-08-22","2006-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(5,"Product E", "5","Black",567.567,"1",5,"ProductLine E","2003-01-22","2003-04-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(6,"Product F", "6","Blue",678.678,"1",6,"ProductLine W","2004-02-22","2005-05-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(7,"Product G", "7","Drak",789.789,"1",7,"ProductLine Q","2005-03-22","2006-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(8,"Product H", "8","Gray",234.123,"1",8,"ProductLine F","2006-04-22","2006-09-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(9,"Product I", "9","Red",543.123,"1",9,"ProductLine R","2007-05-22","2008-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(0,"Product J", "0","Gold",765.123,"1",0,"ProductLine J","2008-06-22","2009-03-22");
4> GO
(1 rows affected)
1>
2>
3>
4>
5> CREATE PROCEDURE spProductCountBySubCategory
6>   @SubID Int
7> AS
8>   DECLARE @Out Int
9>   SELECT @Out = Count(*)
10>   FROM Product
11>   WHERE ProductID = @SubID
12>  RETURN @Out
13>  GO
1>
2>
3>
4>
5> drop PROCEDURE spProductCountBySubCategory;
6> GO
1>
2>
3> drop table Product;
4> GO
1>


Encrypting a Stored Procedure

4>
5> CREATE TABLE employee(
6>    id          INTEGER NOT NULL PRIMARY KEY,
7>    first_name  VARCHAR(10),
8>    last_name   VARCHAR(10),
9>    salary      DECIMAL(10,2),
10>    start_Date  DATETIME,
11>    region      VARCHAR(10),
12>    city        VARCHAR(20),
13>    managerid   INTEGER
14> );
15> GO
1> INSERT INTO employee VALUES (1, "Jason" ,  "Martin", 5890,"2005-03-22","North","Vancouver",3);
2> GO
1> INSERT INTO employee VALUES (2, "Alison",  "Mathews",4789,"2003-07-21","South","Utown",4);
2> GO
1> INSERT INTO employee VALUES (3, "James" ,  "Smith",  6678,"2001-12-01","North","Paris",5);
2> GO
1> INSERT INTO employee VALUES (4, "Celia" ,  "Rice",   5567,"2006-03-03","South","London",6);
2> GO
1> INSERT INTO employee VALUES (5, "Robert",  "Black",  4467,"2004-07-02","East","Newton",7);
2> GO
1> INSERT INTO employee VALUES (6, "Linda" ,  "Green" , 6456,"2002-05-19","East","Calgary",8);
2> GO
1> INSERT INTO employee VALUES (7, "David" ,  "Larry",  5345,"2008-03-18","West","New York",9);
2> GO
1> INSERT INTO employee VALUES (8, "James" ,  "Cat",    4234,"2007-07-17","West","Regina",9);
2> GO
1> INSERT INTO employee VALUES (9, "Joan"  ,  "Act",    6123,"2001-04-16","North","Toronto",10);
2> GO
1>
2> select * from employee;
3> GO
id          first_name last_name  salary       start_Date              region     city                 managerid
----------- ---------- ---------- ------------ ----------------------- ---------- -------------------- -----------
          1 Jason      Martin          5890.00 2005-03-22 00:00:00.000 North      Vancouver                      3
          2 Alison     Mathews         4789.00 2003-07-21 00:00:00.000 South      Utown                          4
          3 James      Smith           6678.00 2001-12-01 00:00:00.000 North      Paris                          5
          4 Celia      Rice            5567.00 2006-03-03 00:00:00.000 South      London                         6
          5 Robert     Black           4467.00 2004-07-02 00:00:00.000 East       Newton                         7
          6 Linda      Green           6456.00 2002-05-19 00:00:00.000 East       Calgary                        8
          7 David      Larry           5345.00 2008-03-18 00:00:00.000 West       New York                       9
          8 James      Cat             4234.00 2007-07-17 00:00:00.000 West       Regina                         9
          9 Joan       Act             6123.00 2001-04-16 00:00:00.000 North      Toronto                       10
1>
2>
3> CREATE PROCEDURE usp_employee
4> WITH ENCRYPTION
5> AS
6> SELECT ID, first_name
7> FROM employee
8> GO
1>
2> exec usp_employee
3> GO
ID          first_name
----------- ----------
          1 Jason
          2 Alison
          3 James
          4 Celia
          5 Robert
          6 Linda
          7 David
          8 James
          9 Joan
1>
2> drop procedure usp_employee
3> GO
1>
2> drop table employee;
3> GO


Filtering for Null Values with a Stored Procedure

4>
5> create table Bankers(
6>    BankerID             Integer,
7>    BankerName           VARCHAR(20),
8>    BankerContactLName   VARCHAR(20),
9>    BankerContactFName   VARCHAR(20),
10>    BankerCity           VARCHAR(20),
11>    BankerState          VARCHAR(20),
12>    BankerZipCode        VARCHAR(20),
13>    BankerPhone          VARCHAR(20)
14> )
15> GO
1>
2> insert into Bankers values (1, "ABC Inc.","Joe","Smith","Vancouver","BC","11111","111-111-1111");
3> GO
(1 rows affected)
1> insert into Bankers values (2, "DEF Inc.","Red","Rice", "New York", "DE","22222","222-222-2222");
2> GO
(1 rows affected)
1> insert into Bankers values (3, "HJI Inc.","Kit","Cat",  "Paris",    "CA","33333","333-333-3333");
2> GO
(1 rows affected)
1> insert into Bankers values (4, "QWE Inc.","Git","Black","Regina",   "ER","44444","444-444-4444");
2> GO
(1 rows affected)
1> insert into Bankers values (5, "RTY Inc.","Wil","Lee",  "Toronto",  "YU","55555","555-555-5555");
2> GO
(1 rows affected)
1> insert into Bankers values (6, "YUI Inc.","Ted","Larry","Calgary",  "TY","66666","666-666-6666");
2> GO
(1 rows affected)
1> insert into Bankers values (7, "OIP Inc.","Yam","Act",  "San Franc","FG","77777","777-777-7777");
2> GO
(1 rows affected)
1> insert into Bankers values (8, "SAD Inc.","Hit","Eat",  "Orland",   "PO","88888","888-888-8888");
2> GO
(1 rows affected)
1> insert into Bankers values (9, "DFG Inc.","Sad","Lee",  "Wisler",   "PL","99999","999-999-9999");
2> GO
(1 rows affected)
1> insert into Bankers values (0, "GHJ Inc.","Bit","Lee",  "Ticker",   "MN","00000","000-000-0000");
2> GO
(1 rows affected)
1>
2>
3> CREATE PROCEDURE usp_SalesPersonInATerritoryOrNot
4> @TID int = NULL
5> AS
6> IF @TID IS NOT NULL
7>     SELECT BankerName
8>     FROM Bankers
9>     WHERE BankerID = @TID
10> ELSE
11>     SELECT BankerName
12>     FROM Bankers
13>     WHERE BankerID IS NULL
14> GO
1>
2> EXEC usp_SalesPersonInATerritoryOrNot 1
3> GO
BankerName
--------------------
ABC Inc.
(1 rows affected)
1> EXEC usp_SalesPersonInATerritoryOrNot NULL
2> GO
BankerName
--------------------
(0 rows affected)
1> EXEC usp_SalesPersonInATerritoryOrNot
2> GO
BankerName
--------------------
(0 rows affected)
1>
2> drop PROCEDURE usp_SalesPersonInATerritoryOrNot;
3> GO
1>
2> drop table Bankers;
3> GO
1>


Managing a Transaction Inside a Stored Procedure

11> CREATE PROC usp_MyProc
12> AS
13> DECLARE
14>   @TranCount  int
15> SET
16>   @TranCount = @@TRANCOUNT
17> IF @TranCount > 0
18>   SAVE TRAN usp_MyProc             -- No existing transaction
19> ELSE
20>   BEGIN TRAN usp_MyProc            -- Transaction in progress
21> --do work here ...
22> IF @@ERROR > 0
23> BEGIN                              -- Failure
24>   RAISERROR ("usp_MyProc - Bailing out. ", 16, 1)
25>   ROLLBACK TRAN usp_MyProc
26>   RETURN
27> END
28> ELSE IF @Trancount = 0             -- Started our own transaction
29>   COMMIT TRAN usp_MyProc           -- Success
30> GO
1>
2> drop procedure usp_MyProc
3> GO


PRINT information out of a PROCEDURE

1> CREATE TABLE Orders (
2>      OrderID int NOT NULL ,
3>      CustomerID nchar (5) NULL ,
4>      EmployeeID int NULL ,
5>      OrderDate datetime NULL ,
6>      RequiredDate datetime NULL ,
7>      ShippedDate datetime NULL ,
8>      ShipVia int NULL ,
9>      Freight money NULL DEFAULT (0),
10>     ShipName nvarchar (40) NULL ,
11>     ShipAddress nvarchar (60) NULL ,
12>     ShipCity nvarchar (15) NULL ,
13>     ShipRegion nvarchar (15) NULL ,
14>     ShipPostalCode nvarchar (10) NULL ,
15>     ShipCountry nvarchar (15) NULL
16> )
17> GO
1>
2>
3> INSERT INTO Orders VALUES (10248,"1",5,"7/4/1996","8/1/2001","7/16/2001",3,32.38,"V","A","R",        NULL,N"51100","France")
9> go
1>
2>
3>    create PROCEDURE spCursorScope
4>    AS
5>    DECLARE @Counter      int,
6>            @OrderID      int,
7>            @CustomerID   varchar(5)
8>    DECLARE CursorTest cursor
9>    LOCAL
10>    FOR
11>       SELECT OrderID, CustomerID
12>       FROM Orders
13>
14>    SELECT @Counter = 1
15>    OPEN CursorTest
16>    FETCH NEXT FROM CursorTest INTO @OrderID, @CustomerID
17>    PRINT "Row " + CONVERT(varchar,@Counter) + " has an OrderID of " +
18>          CONVERT(varchar,@OrderID) + " and a CustomerID of " + @CustomerID
19>
20>    WHILE (@Counter<=5) AND (@@FETCH_STATUS=0)
21>    BEGIN
22>          SELECT @Counter = @Counter + 1
23>          FETCH NEXT FROM CursorTest INTO @OrderID, @CustomerID
24>          PRINT "Row " + CONVERT(varchar,@Counter) + " has an OrderID of " +
25>          CONVERT(varchar,@OrderID) + " and a CustomerID of " + @CustomerID
26>    END
27>    GO
1>
2>    drop PROCEDURE spCursorScope;
3>    GO
1>
2>    drop table Orders;
3>    GO


Procedure as a view

6> CREATE TABLE Shippers (
7>      ShipperID int NOT NULL ,
8>      CompanyName nvarchar (40) NOT NULL ,
9>      Phone nvarchar (24) NULL
10> )
11> GO
1>
2>
3> INSERT Shippers VALUES(1,"Express","(503) 555-9831")
4> INSERT Shippers VALUES(2,"Package","(503) 555-3199")
5> INSERT Shippers VALUES(3,"Shipping","(503) 555-9931")
6> go
(1 rows affected)
(1 rows affected)
(1 rows affected)
1>    CREATE PROC spShippers
2>    AS
3>       SELECT * FROM Shippers
4>    GO
1>    EXEC spShippers
2>    GO
ShipperID   CompanyName                              Phone
----------- ---------------------------------------- ------------------------
          1 Express                                  (503) 555-9831
          2 Package                                  (503) 555-3199
          3 Shipping                                 (503) 555-9931
(3 rows affected)
1>    drop PROC spShippers;
2>    GO
1>
2>    drop table Shippers;
3>    GO


Return a value out of a procedure

3>
4>
5>
6> CREATE TABLE Product(
7>     ProductID               int                NOT NULL,
8>     Name                    nvarchar(25)       NOT NULL,
9>     ProductNumber           nvarchar(25)               ,
10>     Color                   nvarchar(15)       NULL,
11>     StandardCost            money              NOT NULL,
12>     Size                    nvarchar(5)        NULL,
13>     Weight                  decimal(8, 2)      NULL,
14>     ProductLine             nchar(20)           NULL,
15>     SellStartDate           datetime           NOT NULL,
16>     SellEndDate             datetime           NULL
17> )
18> GO
1> insert into Product values(1,"Product A", "1","Red",123.123,"1",1,"ProductLine A","1999-03-22","2000-03-22");
2> GO
(1 rows affected)
1> insert into Product values(2,"Product B", "2","Yellow",234.234,"1",3,"ProductLine B","2000-03-22","2001-03-22");
2> GO
(1 rows affected)
1> insert into Product values(3,"Product C", "3","Pink",345.345,"1",3,"ProductLine V","2001-09-22","2006-02-22");
2> GO
(1 rows affected)
1> insert into Product values(4,"Product D", "4","White",456.456,"1",4,"ProductLine D","2002-08-22","2006-03-22");
2> GO
(1 rows affected)
1> insert into Product values(5,"Product E", "5","Black",567.567,"1",5,"ProductLine E","2003-01-22","2003-04-22");
2> GO
(1 rows affected)
1> insert into Product values(6,"Product F", "6","Blue",678.678,"1",6,"ProductLine W","2004-02-22","2005-05-22");
2> GO
(1 rows affected)
1> insert into Product values(7,"Product G", "7","Drak",789.789,"1",7,"ProductLine Q","2005-03-22","2006-03-22");
2> GO
(1 rows affected)
1> insert into Product values(8,"Product H", "8","Gray",234.123,"1",8,"ProductLine F","2006-04-22","2006-09-22");
2> GO
(1 rows affected)
1> insert into Product values(9,"Product I", "9","Red",543.123,"1",9,"ProductLine R","2007-05-22","2008-03-22");
2> GO
(1 rows affected)
1> insert into Product values(0,"Product J", "0","Gold",765.123,"1",0,"ProductLine J","2008-06-22","2009-03-22");
2> GO
(1 rows affected)
1>
2>
3> CREATE PROCEDURE spProductCountBySubCategory
4>   @SubID Int
5> AS
6>   DECLARE @Out Int
7>   SELECT @Out = Count(*)
8>   FROM Product
9>   WHERE ProductID = @SubID
10> RETURN @Out
11> GO
1>
2>
3>
4>
5> drop PROCEDURE spProductCountBySubCategory;
6> GO
1>
2>
3> drop table Product;
4> GO
1>


Returning Values from a View as Stored Procedure Output Parameters

4> create table Billings (
5>     BankerID           INTEGER,
6>     BillingNumber      INTEGER,
7>     BillingDate        datetime,
8>     BillingTotal       INTEGER,
9>     TermsID            INTEGER,
10>     BillingDueDate     datetime ,
11>     PaymentTotal       INTEGER,
12>     CreditTotal        INTEGER
13>
14> );
15> GO
1>
2> INSERT INTO Billings VALUES (1, 1, "2005-01-22", 165, 1,"2005-04-22",123,321);
3> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (2, 2, "2001-02-21", 165, 1,"2002-02-22",123,321.);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (3, 3, "2003-05-02", 165, 1,"2005-04-12",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (4, 4, "1999-03-12", 165, 1,"2005-04-18",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (5, 5, "2000-04-23", 165, 1,"2005-04-17",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (6, 6, "2001-06-14", 165, 1,"2005-04-18",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (7, 7, "2002-07-15", 165, 1,"2005-04-19",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (8, 8, "2003-08-16", 165, 1,"2005-04-20",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (9, 9, "2004-09-17", 165, 1,"2005-04-21",123,321);
2> GO
(1 rows affected)
1> INSERT INTO Billings VALUES (0, 0, "2005-10-18", 165, 1,"2005-04-22",123,321);
2> GO
(1 rows affected)
1>
2>
3>
4> CREATE PROCEDURE usp_MinMaxSubTotal
5> @minSubTotal money OUTPUT,
6> @maxSubTotal money OUTPUT
7> AS
8> SET @minSubTotal =
9>     (SELECT TOP 1 BillingTotal
10>         FROM Billings ORDER BY BillingTotal)
11> SET @maxSubTotal =
12>     (SELECT TOP 1 BillingTotal
13>         FROM Billings ORDER BY BillingTotal DESC)
14> GO
1>
2> DECLARE @lclmin money, @lclmax money
3> EXEC usp_MinMaxSubTotal @minSubTotal = @lclmin OUTPUT,
4>     @maxSubTotal = @lclmax OUTPUT
5> SELECT @lclmin "Min. SubTotal", @lclmax "Max. SubTotal"
6> GO
Min. SubTotal         Max. SubTotal
--------------------- ---------------------
             165.0000              165.0000
(1 rows affected)
1>
2> drop PROCEDURE usp_MinMaxSubTotal ;
3> GO
1>
2>
3> drop table Billings;
4> GO


Stored Procedures as Parameterized Views

3>
4>
5>
6> CREATE TABLE Product(
7>     ProductID               int                NOT NULL,
8>     Name                    nvarchar(25)       NOT NULL,
9>     ProductNumber           nvarchar(25)               ,
10>      Color                   nvarchar(15)       NULL,
11>      StandardCost            money              NOT NULL,
12>      Size                    nvarchar(5)        NULL,
13>      Weight                  decimal(8, 2)      NULL,
14>      ProductLine             nchar(20)           NULL,
15>      SellStartDate           datetime           NOT NULL,
16>      SellEndDate             datetime           NULL
17>  )
18>  GO
1> insert into Product values(1,"Product A", "1","Red",123.123,"1",1,"ProductLine A","1999-03-22","2000-03-22");
2> GO
(1 rows affected)
1>
2>
3> insert into Product values(2,"Product B", "2","Yellow",234.234,"1",3,"ProductLine B","2000-03-22","2001-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(3,"Product C", "3","Pink",345.345,"1",3,"ProductLine V","2001-09-22","2006-02-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(4,"Product D", "4","White",456.456,"1",4,"ProductLine D","2002-08-22","2006-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(5,"Product E", "5","Black",567.567,"1",5,"ProductLine E","2003-01-22","2003-04-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(6,"Product F", "6","Blue",678.678,"1",6,"ProductLine W","2004-02-22","2005-05-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(7,"Product G", "7","Drak",789.789,"1",7,"ProductLine Q","2005-03-22","2006-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(8,"Product H", "8","Gray",234.123,"1",8,"ProductLine F","2006-04-22","2006-09-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(9,"Product I", "9","Red",543.123,"1",9,"ProductLine R","2007-05-22","2008-03-22");
4> GO
(1 rows affected)
1>
2>
3> insert into Product values(0,"Product J", "0","Gold",765.123,"1",0,"ProductLine J","2008-06-22","2009-03-22");
4> GO
(1 rows affected)
1>
2>
3>
4>
5>
6> CREATE VIEW vProductCosts
7> AS
8> SELECT ProductID, Name, ProductNumber, StandardCost
9> FROM Product
10> GO
1>
2> CREATE PROCEDURE spProductCosts
3> AS
4> SELECT ProductID, Name, ProductNumber, StandardCost
5> FROM Product
6> GO
1>
2> EXECUTE spProductCosts
3> GO
ProductID   Name                      ProductNumber             StandardCost
----------- ------------------------- ------------------------- ---------------------
          1 Product A                 1                                      123.1230
          2 Product B                 2                                      234.2340
          3 Product C                 3                                      345.3450
          4 Product D                 4                                      456.4560
          5 Product E                 5                                      567.5670
          6 Product F                 6                                      678.6780
          7 Product G                 7                                      789.7890
          8 Product H                 8                                      234.1230
          9 Product I                 9                                      543.1230
          0 Product J                 0                                      765.1230
(10 rows affected)
1>
2> drop PROCEDURE spProductCosts;
3> GO
1>
2> drop VIEW vProductCosts;
3> GO
1>
2> drop table Product;
3> GO