DECODE Function Examples | Teradata Vantage - 17.10 - Example: Decoding IDs - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1145-171K
Language
English (United States)

The following query:

SELECT DECODE(country_id, 1, 'United States',
                          2, 'England',
                          3, 'France',
                          'United States')
    FROM customers; 

returns:

  • 'United States' if the country_id is 1
  • 'England' if the country_id is 2
  • 'France' if the country_id is 3
  • 'United States' if the country_id is not equal to 1, 2, or 3