Testing and Branching Commands - Basic Teradata Query

Basic Teradata Query Reference

Product
Basic Teradata Query
Release Number
15.00
Language
English (United States)
Last Update
2018-09-25
dita:id
B035-2414
lifecycle
previous
Product Category
Teradata Tools and Utilities

Testing and Branching Commands

There are two commands that perform these functions:

 

Command Name

Function

IF...THEN...

Tests the condition stated in the IF clause, then resumes command execution based on the outcome of the test.

GOTO

When used with the THEN clause of the IF...THEN... command, specifies the destination of the branch operation.

IF... THEN... Command Process

The BTEQ IF...THEN... command is a conventional condition-testing command. After testing the condition stated in the IF clause, BTEQ resumes command execution as follows:

 

If

Then

If the condition stated in the IF clause is TRUE

BTEQ executes the command stated in the THEN clause.

If the condition stated in the IF clause is FALSE

BTEQ does not execute the command stated in the THEN clause, it executes the next command.

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

GOTO Command Process

The BTEQ GOTO command is a branching command that can be used with the THEN clause of the IF...THEN... command to identify the destination of the branch operation. Refer to “GOTO” on page 187.

Enter the GOTO command with a labelname parameter, which designates the skip destination. Identify the skip destination with a LABEL command. Note that only the first 30 characters of the labelname parameter are significant.

Note: The GOTO command can be used only to skip forward in a script. Attempting to branch back to a statement listed before the GOTO command causes unexpected results. All subsequent lines in the script are skipped until the target LABEL command is found or BTEQ reaches the end of the script. Therefore, when using the GOTO command, the LABEL command that identifies the lablename must appear later in the script.