Show TOC

EXECUTE Statement [T-SQL]Locate this document in the navigation structure

Invokes a procedure, as an SAP ASE-compatible alternative to the CALL statement.

Syntax
EXECUTE<@return_status> = ] [<owner>.]<procedure_name>
   ... { [ <@parameter-name> = ] <expression>
   | [ <@parameter-name> = ] <@variable><output> ] } ,...
Examples

(back to top)

  • Example 1 creates the procedure p1:
    CREATE PROCEDURE p1( @var INTEGER = 54 )
    AS
    PRINT 'on input @var = %1! ', @var
    DECLARE @intvar integer
    SELECT @intvar=123
    SELECT @var=@intvar
    PRINT 'on exit @var = %1!', @var;

    Execute the procedure, supplying the input value of 23 for the parameter. If you are connected from an Open Client application, PRINT messages are displayed on the client window. If you are connected from an ODBC or Embedded SQL application, messages display on the database server window.

    EXECUTE p1 23

    An alternative way of executing the procedure, which is useful if there are several parameters:

    EXECUTE p1 @var = 23

    Execute the procedure, using the default value for the parameter:

    EXECUTE p1

    Execute the procedure and store the return value in a variable for checking return status:

    EXECUTE @status = p1 23
Usage

(back to top)

EXECUTE executes a stored procedure, optionally supplying procedure parameters and retrieving output values and return status information.

EXECUTE is implemented for Transact-SQL compatibility, but can be used in either Transact-SQL or SAP IQ batches and procedures.

Note

You cannot reference a Table UDF in an EXECUTE statement.

Permissions

(back to top)

Must be the owner of the procedure, have EXECUTE permission for the procedure, or have the EXECUTE ANY PROCEDURE system privilege.