Executing a Stored Procedure

When you need to execute a stored procedure, use the Transact-SQL EXECUTE statement. You can execute a stored procedure without using the EXECUTE keyword if the stored procedure is the first statement in the batch.

Parameter values can be supplied if a stored procedure is written to accept them.


Note If you supply parameters in the form @parameter = value, you can supply them in any order. You can also omit parameters for which defaults have been supplied. If you supply one parameter in the form @parameter = value, you must supply all subsequent parameters this way. If you do not supply parameters in the form @parameter = value, you must supply them in the order given in the CREATE PROCEDURE statement.
When executing a stored procedure, the server rejects any parameters that were not included with the parameter list during procedure creation. Any parameter passed by reference (explicitly passing the parameter name) is not accepted if the parameter name does not match.
Although you can omit parameters for which defaults have been supplied, you can only truncate the list of parameters. For example, if a stored procedure has five parameters, you can omit both the fourth and the fifth parameters, but you cannot skip the fourth and still include the fifth unless you supply parameters in the form @parameter = value.


The default value of a parameter, if defined for the parameter in the stored procedure, is used when:

To execute a stored procedure that is grouped with other stored procedures of the same name, specify the identification number of the stored procedure within the group. For example, to execute the second stored procedure in the group my_proc, execute:

EXECUTE my_proc;2

  

To execute a stored procedure

See Also
Batches Execution Characteristics of Extended Stored Procedures
Common SQL Server Profiler Scenarios Specifying Parameters
Debugging an Extended Stored Procedure SQL Stored Procedures
Returning Data Using a Return Code Recompiling a Stored Procedure

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.