Export (0) Print
Expand All

WHENEVER

SQL Server 2000

The WHENEVER statement specifies the action (CONTINUE, GOTO, or CALL) to be taken when one of three possible SQLCODE conditions is met following the execution of an Embedded SQL statement.

Syntax

WHENEVER {SQLWARNING | SQLERROR | NOT FOUND} {CONTINUE | GOTO stmt_label | CALL function()}

Arguments

SQLWARNING

Specifies that an Embedded SQL warning occurred and was stored in the SQLCA data structure.

SQLERROR

Specifies that a Microsoft® SQL Server™ 2000 message was received and stored in the SQLCA data structure.

NOT FOUND

Specifies that no rows were returned from a valid and properly executed SELECT statement, or that a FETCH statement returned no more rows, and that SQLCODE was set to 100 in the SQLCA data structure.

CONTINUE (default)

Specifies running the next physically sequential statement in the source program.

stmt_label

Is the place in the program where control is assumed.

function()

Is a function in your application. Parentheses () are required following the function name (function()). If parentheses are omitted, the function is not called. The function can include parameters.

Remarks

SQLCODE conditions have the following values.

Condition Value Example
No error 0  
NOT FOUND 100 Fetch past end of results
SQLWARNING +1 Data truncation on output
SQLERROR < 0 (negative) Constraint violation

For more information about how to handle specific error conditions programmatically, using SQLSTATE values, see SQLSTATE Messages.

The following SQLCODE values are revised in ESQL/C version 6.5 and are carried to version 7.0.

Condition New value Previous value
Singleton SELECT statement returns more than 1 row -1 1
NULL value returns, but no indicator variable declared -1 0
Second attempt to open cursor without corresponding close while CLOSE_ON_COMMIT is in force -1 0
Server error encountered on cursor open -nnn..., where nnn is a server message number -19521

WHENEVER statement actions are related to the position of statements in the source code, not in the run sequence. The default is CONTINUE for all conditions.

Examples
EXEC SQL WHENEVER sqlerror GOTO displayca;
   .
   .
   .
EXEC SQL WHENEVER sqlerror CALL error_funct(param);

See Also

Using the WHENEVER Statement

Advanced Programming

Show:
© 2015 Microsoft