Parameterization: @parameter_name [AS] datatype [= default|NULL] [VARYING] [OUTPUT|OUT] : Parameter « Procedure Function « SQL Server / T-SQL Tutorial






10>
11>
12> CREATE TABLE Shippers (
13>     ShipperID int NOT NULL ,
14>     CompanyName nvarchar (40) NOT NULL ,
15>     Phone nvarchar (24) NULL
16> )
17> 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 spInsertShipper
2>       @CompanyName   nvarchar(40),
3>       @Phone         nvarchar(24)
4>    AS
5>       INSERT INTO Shippers (CompanyName,Phone )
6>       VALUES
7>          (@CompanyName, @Phone)
8>
9>    GO
1>
2>    EXEC spInsertShipper 'Speedy Shippers, Inc.', '(503) 555-5566'
3>    GO
Msg 515, Level 16, State 2, Server J\SQLEXPRESS, Procedure spInsertShipper, Line 5
Cannot insert the value NULL into column 'ShipperID', table 'master.dbo.Shippers'; column does not allow nulls. INSERT fails.
The statement has been terminated.
1>
2>    drop PROC spInsertShipper;
3>    drop table Shippers;
4>    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