Call procedure with parameter name : Parameter « Procedure Function « SQL Server / T-SQL Tutorial






2> CREATE PROCEDURE pass_params
3> @param0 int=NULL,   -- Defaults to NULL
4> @param1 int=1,      -- Defaults to 1
5> @param2 int=2       -- Defaults to 2
6> AS
7> SELECT @param0, @param1, @param2
8> GO
1>
2> EXEC pass_params          -- PASS NOTHING - ALL Defaults
3> GO

----------- ----------- -----------
       NULL           1           2
1>
2> EXEC pass_params 0, 10, 20    -- PASS ALL, IN ORDER
3> GO

----------- ----------- -----------
          0          10          20
1>
2> EXEC pass_params @param2=200, @param1=NULL
3> -- Explicitly identify last two params (out of order)
4> GO

----------- ----------- -----------
       NULL        NULL         200
1>
2> EXEC pass_params 0, DEFAULT, 20
3> -- Let param1 default. Others by position.
4> GO

----------- ----------- -----------
          0           1          20
1>
2> drop PROCEDURE pass_params ;
3> 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