EXECUTE Statement (version 6.5)

Specifies the keyword DEFAULT in place of a parameter.

For additional syntax information for the EXECUTE statement, see the Microsoft SQL Server Transact-SQL Reference.

Syntax

EXECute procedure_name [parameter [, parameter2 [..., parameterN ]]]

where

procedure_name
Specifies the name of the procedure to call.
@parameter=
parameter_value
| @parameter_name = parameter_value
| @parameter_name = DEFAULT
| DEFAULT
@parameter_value
Is the value that is supplied to the procedure.
parameter_name
Is the name of the parameter.
DEFAULT
Supplies the default value of the parameter as defined in the procedure.

Remarks

The DEFAULT keyword allows you to generically specify that a parameter's default value be used.

When the procedure expects a value for a parameter that does not have a defined default and either a parameter is missing or the DEFAULT keyword is specified, an error occurs.

Example

This example creates a stored procedure with default values for the first and third parameters. When the procedure is run, these defaults are inserted for the first and third parameters if no value is passed in the call or if the default is specified. Note the various ways the DEFAULT keyword can be used.

--- create the stored procedure ---
CREATE PROC proc_calculate_taxes (@p1 SMALLINT = 42, @p2 CHAR(1), @p3 VARCHAR(8) = 'CAR')
  

The proc_calculate_taxes stored procedure can be executed in many combinations:

EXECUTE proc_calculate_taxes @p2 = 'A'
EXECUTE proc_calculate_taxes 69, 'B'
EXECUTE proc_calculate_taxes 69, 'C', 'House'
EXECUTE proc_calculate_taxes @p1 = DEFAULT, @p2 = 'D'
EXECUTE proc_calculate_taxes DEFAULT, @p3 = 'Local', @p2 = 'E'
EXECUTE proc_calculate_taxes 69, 'F', @p3 = DEFAULT
EXECUTE proc_calculate_taxes 95, 'G', DEFAULT
EXECUTE proc_calculate_taxes DEFAULT, 'H', DEFAULT
EXECUTE proc_calculate_taxes DEFAULT, 'I', @p3 = DEFAULT