Simple CASE Statement - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

In this form of the conditional statement, you can run a list of SQL statements, including control statements, associated with at most one WHEN clause or ELSE clause, depending on whether operand_1 (value-expression) equals operand_2 (value-expression).

The WHEN clauses are evaluated in the order specified in the CASE statement. The process of evaluation is as follows:

  1. The first WHEN clause is evaluated.
    • If the value-expression (operand_1) specified in the CASE clause is equal to the value-expression (operand_2) in the WHEN clause, the statements of that WHEN clause are run.
    • Control goes to the next statement in the stored procedure.If the value expressions are not equal, then the next WHEN clause, if any, is evaluated.
  2. All subsequent WHEN clauses are evaluated as described in stage 1.
  3. When there are no more WHEN clauses to evaluate, the ELSE clause, if any, is taken up and the statements of the ELSE clause are run. Control goes to the next statement in the stored procedure.
  4. If there is no ELSE clause and the value-expression in the CASE clause does not find a match in any of the WHEN clauses,
  • A runtime exception ("Case not found for CASE statement", SQLSTATE='20000', SQLCODE = 7601) occurs.
  • The execution of the CASE statement is terminated.