Purpose
Tests the validity of the condition stated in the IF clause.
Condition Status |
Result |
True |
BTEQ executes the action stated in the THEN clause. |
False |
BTEQ does not process the action in the THEN clause and proceeds to the next command statement. |
Syntax
where:
Syntax Element |
Description |
bteq_command |
BTEQ command or Teradata SQL statement to be executed when the IF condition is true. |
n |
A number in any of the following ranges: Or, if specifying the ERRORLEVEL option, n is an assigned error level number that can be 0, 2, 4, 6, 8, or higher. |
operator |
One of the following comparison operators: = (equal to) |
Usage Notes
Specified Option |
Results |
ERRORCODE |
BTEQ substitutes for ERRORCODE the value of the error code that was generated by the last Teradata SQL request. |
|
If the last request completed successfully, the value of ERRORCODE is zero. |
ERRORLEVEL |
BTEQ returns the severity level code associated with that error level. |
ACTIVITYCOUNT |
BTEQ substitutes for ACTIVITYCOUNT the value of the number of rows affected by the last Teradata SQL statement. For a request resulting in a selection of rows, this is the number of rows returned to BTEQ from the database. |
The IF...THEN... command is valid in a Teradata SQL macro, if the THEN clause includes a valid BTEQ command that is also valid in a Teradata SQL macro.
Example
To transfer control to the script section labelled as NXTREPORT when the error code generated by the last Teradata SQL request is 3000, enter the following command:
.IF ERRORCODE = 3000 THEN .GOTO NXTREPORT
Example
To set BTEQ’s return code to 1 if a Teradata SQL request finds no rows, enter the following command:
.IF ACTIVITYCOUNT = 0 THEN .QUIT 1
Example
When used in a Teradata SQL macro, the IF...THEN... command has the following format:
ECHO '.IF ERRORCODE = 3000 THEN .REMARK ''Next'' ';