parameters can be passed explicitly by value : Parameter « Procedure Function « SQL Server / T-SQL Tutorial






2>
3> CREATE TABLE Product(
4>     ProductID               int                NOT NULL,
5>     Name                    nvarchar(25)       NOT NULL,
6>     ProductNumber           nvarchar(25)               ,
7>     Color                   nvarchar(15)       NULL,
8>     StandardCost            money              NOT NULL,
9>     Size                    nvarchar(5)        NULL,
10>      Weight                  decimal(8, 2)      NULL,
11>      ProductLine             nchar(20)           NULL,
12>      SellStartDate           datetime           NOT NULL,
13>      SellEndDate             datetime           NULL
14>  )
15>  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 spEmployeeByCost
6> @SubID Int, @Cost Money
7> AS
8> SELECT ProductID, Name, ProductNumber, StandardCost
9> FROM Product
10> WHERE ProductID = @SubID
11> AND StandardCost > @Cost
12>  GO
1>
2>
3> EXECUTE spEmployeeByCost 1, $1000.00
4> GO
ProductID   Name                      ProductNumber             StandardCost
----------- ------------------------- ------------------------- ---------------------

(0 rows affected)
1>
2> --Or the parameters can be passed explicitly by value. If the parameters are supplied by value it doesn't matter in what order they are supplied:
3> EXECUTE spEmployeeByCost @Cost = $1000.00, @SubID = 1
4> GO
ProductID   Name                      ProductNumber             StandardCost
----------- ------------------------- ------------------------- ---------------------

(0 rows affected)
1> drop table Product;
2> GO








21.13.Parameter
21.13.1.The syntax for declaring parameters
21.13.2.Parameterization: @parameter_name [AS] datatype [= default|NULL] [VARYING] [OUTPUT|OUT]
21.13.3.Procedure with default parameter value
21.13.4.Check parameter value with if statement
21.13.5.Procedure with two parameters
21.13.6.Passing the ORDER BY Column as a Parameter, Using a Column Number
21.13.7.Passing the ORDER BY Column as a Parameter, Using Dynamic Execution
21.13.8.Select using value from parameter
21.13.9.Call procedure with parameter name
21.13.10.Parameter with null default value
21.13.11.Pass column as the parameter
21.13.12.parameters can be passed explicitly by value
21.13.13.stored procedure can be executed with the parameter and assigned value
21.13.14.Wildcards in Parameters
21.13.15.Check value range for input parameter
21.13.16.Code that omits both optional parameters
21.13.17.Code that omits one optional parameter
21.13.18.Code that passes the parameters by position
21.13.19.Code that passes the parameters by name
21.13.20.Stored Procedure with Cursor Parameter