CALL Statement

Calls a stored procedure.

Syntax

CALL procname( {param{,{param}}...} )

SET varname = CALL procname( {param{,{param}}...} )

?= CALL procname( {param{,{param}}...} )

Syntax Elements

procname
The name of the procedure.

varname
The name of a variable to which the value returned by the procedure will be assigned. If the procedure does not return a value, an error occurs.

param
An expression that evaluates to a value of the type declared for this argument when the procedure was created. If you omit a parameter that has a default value, the default value will be used; under these circumstances, you must include the corresponding comma as a placeholder.

Comments

See SQL Stored Procedures for details of how to write and use SQL procedures.

The second form of the syntax can only be used when calling a procedure from within another procedure.

The third form of the syntax assigns the value returned to an ODBC dynamic parameter. This can only be done from within application code.

Note that the full ODBC syntax for calling a stored procedure requires the use of an ODBC escape sequence:

{{?=}CALL procname( {param{,param{?}} )}

or:

--(*vendor(Microsoft),product(ODBC)
{?=}CALL procname( {param{,param{?}} )--

Reality fully supports these escape sequences, but they are not mandatory.

Examples

DECLARE @A DECIMAL(6,2)
DECLARE @B DECIMAL(6,2)
CALL EX5(@A,@B)

Declares two variables, @A and @B, and passes them as parameters to the EX5 procedure. On return, the variables hold the procedure results.

DECLARE @A DECIMAL(6,2)
SET @A = CALL EX7(1)

Declares variable @A and sets its value to the result of procedure EX7.

See Also

CREATE PROCEDURE statement.