15.00 - SQL Expressions - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)

SQL Expressions

SQL expressions specify a value, allowing you to perform arithmetic and logical operations and to generate new values or Boolean results from literals and stored values. An expression can consist of any of the following things:

  • Column name
  • Literal (sometimes referred to as a constant)
  • Function
  • USING variable
  • Parameter
  • Parameter marker (question mark (?) placeholder)
  • Combination of column names, literals, and functions connected by operators
  • Types of Expressions

    SQL expressions generally fall into the following categories.

     

    Type

    Description

    Numeric expression

    Expressions are generally classified by the type of result they produce.

    For example, a numeric expression consists of a column name, literal, function, or combination of column names, literals, and functions connected by arithmetic operators where the result is a numeric type.

    String expression

    DateTime expression

    Interval expression

    Period expression, including a derived period

    CASE expression

    A CASE expression consists of a set of WHEN/THEN clauses and an optional ELSE clause.

    A valued CASE expression tests for the first WHEN expression that is equal to a test expression and returns the value of the matching THEN expression. If no WHEN expression is equal to the test expression, CASE returns the ELSE expression, or, if omitted, NULL.

    A searched CASE expression tests for the first WHEN expression that evaluates to TRUE and returns the value of the matching THEN expression. If no WHEN expression evaluates to TRUE, CASE returns the ELSE expression, or, if omitted, NULL.

    Examples of Expressions

     

    Expression

    Description

    'Test Tech' 

    Character string literal

    1024

    Numeric literal

    Employee.FirstName 

    Column name

    Salary * 12 + 100 

    Arithmetic expression producing a numeric value

    INTERVAL '10' MONTH * 4

    Interval expression producing an interval value

    CURRENT_DATE + INTERVAL '2' DAY

    DateTime expression producing a DATE value

    CURRENT_TIME - INTERVAL '1' HOUR

    DateTime expression producing a TIME value

    'Last' || ' Order'

    String expression producing a character string value

    CASE x
      WHEN 1
      THEN 1001
      ELSE 1002
    END

    Valued CASE conditional expression producing a numeric value