How BTEQ Uses Test Conditions and Branching | Basic Teradata Query - 17.00 - Testing and Branching - Basic Teradata Query

Basic Teradata® Query Reference

Basic Teradata Query
June 2020
Programming Reference

Testing refers to the outcome of the most recent SQL request, the one that immediately precedes an IF or ELSE command. Branching is based on the outcome of that earlier request.

When writing BTEQ scripts to run in batch mode, use commands to test conditions and respond to the result by executing only specific instruction blocks or skipping ahead to another portion of the script.

There are three types of command sequences that can be employed:

Command Name Function
IF...THEN... The IF...THEN command enables branching by way of a single-instruction executed, or not, based on the explicitly specified conditions for the IF clause. If they resolve to TRUE, BTEQ does not execute the instruction stated in the THEN clause, it executes the next command.
GOTO...LABEL The GOTO command specifies a label name value. BTEQ will immediately start skipping forward through subsequent input instructions until it finds a LABEL command that specifies the matching name. It can only skip forward and will continue to do so until it finds the label or reaches the end of the script. Therefore, when using the GOTO command, the LABEL command that identifies the label name must appear later in the script.
IF...ELSEIF...ELSE...END This sequence of commands enables branching by way of multi-instruction block execution or bypass. Using ELSEIF and ELSE blocks is optional. The first set of conditions (explicit or implicit) that resolves to TRUE for the IF, ELSEIF and ELSE commands dictates the branching that occurs.