THEN/ELSE Character Type Expressions - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

The following rules apply to CASE expressions where the data types of all of the THEN/ELSE expressions are character:

  • The result of the CASE expression is also a character data type, with the length equal to the maximum length of the different character data types of the THEN/ELSE expressions.
  • If the data types of all of the THEN/ELSE expressions are CHARACTER (or CHAR), the result data type is CHARACTER. If one or more expressions are VARCHAR (or LONG VARCHAR), the result data type is VARCHAR.
  • The server character set of the result is determined as follows:
    • If the CASE expression contains 1 nonliteral character expression and 1 or more literals, then Vantage tries to translate every literal to the character set of the nonliteral. If the translations are successful, then the character set of the nonliteral is used for the result data type. If the translations are not successful, the server character set of the result is Unicode.
    • If the CASE expression contains more than 1 nonliteral character expression and 1 or more literals, then:

      If all of the nonliteral expressions have the same character set, then Vantage uses this character set as the common data type. Otherwise, if the nonliteral expressions have differing character sets, then Vantage uses the Unicode character set as the common data type.

      Vantage tries to translate every literal to the character set of the common data type. If the translations are successful, then the result data type has the character set of the common data type. If the translations are not successful, the server character set of the result is Unicode.