Using Conditional Logic in a Query - SQL Assistant

Teradata SQL Assistant for Microsoft Windows User Guide

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

Using Conditional Logic in a Query

The following conditional logic commands can be used within queries.

Table Legend

  • { }–Items in curly brackets are requirements.
  • [ ]–Items in square brackets are optional.
  • label–A string that does not contain any blank spaces or tabs.
  • oper–One of the following operators:
  •  

    =

    >

    <

    >=

    <=

    <>

    !=

    ^=

    ~=

     

  • n–An integer.
  • value–Any string.
  • filename–A fully qualified file name.
  •  

    Command

    Description

    .IF {ACTIVITYCOUNT} oper n [THEN] {.GOTO label}

          {ERRORCODE         }                            {.EXIT [n]     }

    If the condition is true, the action is performed. Otherwise the flow continues to the following statement.

    This command cannot be used before the first SQL statement.

    .GOTO label

    The next statement executed is the statement following the .LABEL command.

    .LABEL label

    Defines the destination of a .GOTO command.

               [ n                                    ]

    .EXIT [ ERRORCODE            ]

               [ ACTIVITYCO[UNT]]

    Execution terminates at this command. The optional parameter is used as the result code for the query. Zero indicates a successful query, any other value indicates failure.

    .QUIT

    Performs the same function as the .EXIT command.

    .SET value

    This command is for BTEQ compatibility only. This command is ignore. Unlike BTEQ, The .SET prefix is required for Teradata SQL Assistant to recognize and ignore a command.

    .RUN filename

    Execute the query contained in the specified filename. The RUN command must be the first and only statement executed.

    Usage Notes

  • The period (.) before the RUN command is optional for backward compatibility.
  • The period (.) before other commands (except .SET) is optional when connected to a Teradata Database, but required when connected to other databases.
  • The period for the .SET command is mandatory even when connected to a Teradata Database.
  • [Optional] All commands can be followed by a semi-colon. This is not required unless you need compatibility with BTEQ.
  • To use conditional logic commands based on the ERRORCODE, you must first disable the Stop query execution if an SQL error occurs option on the Query tab of the Options dialog box. Otherwise Teradata SQL Assistant might stop processing the query before it attempts to evaluate your conditional logic. See “Setting Query Options” on page 67.