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

Basic Teradata® Query Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
Lake
VMware
Product
Basic Teradata Query
Release Number
20.00
Published
October 2023
ft:locale
en-US
ft:lastEdition
2025-04-02
dita:mapPath
gxl1691484661681.ditamap
dita:ditavalPath
obe1474387269547.ditaval
dita:id
psp1479308573013
Product Category
Teradata Tools and Utilities

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.