GOTO - Basic Teradata Query

Basic Teradata Query Reference

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

Purpose  

Skips over all intervening BTEQ commands and SQL statements until a specified label is encountered, then resumes processing in sequence.

Syntax  

where:

 

Syntax Element

Description

labelname

The user-defined name of the statement to which control transfers, as specified by a subsequent LABEL command.

For more information, see “LABEL” on page 220.

Usage Notes  

The GOTO command only transfers control forward; it cannot transfer control to a statement that occurs before the GOTO command. If a LABEL command statement is not provided which matches the labelname, BTEQ terminates the script.

The GOTO command is frequently used with the IF...THEN... command.

Example  

The following example uses GOTO commands to transfer control forward to the LABEL statements SECTIONA or SECTIONB:

   database workforce;
   select empno
   ,hours from charges
   where  proj_id = 'oe1-0001'
   order by empno;
   .IF activitycount = 0 then .GOTO SECTIONA
   .IF activitycount >= 1 then .GOTO SECTIONB
   .label SECTIONA 
   .REMARK 'Zero Hours on Account'
   .label SECTIONB
   .REMARK 'Total Hours on Account'
   .logoff       
   .exit