Friday, October 12, 2018

Use the SQL function DECODE in ODBC

DECODE SQL function is similar to an If-Then-Else statement. It compares the value of the first argument expression with each search_expression and, if a match is found, returns the corresponding match_expression. If no match is found, then the function returns the  default_expression. If a default_expression is not specified and no match is found, the function returns a null value. Below is a sample Select statement.
 
SYNTAX
DECODE ( expression, search_expression, match_expression
[ , search_expression, match_expression ...]
[ , default_expression ] )
 
EXAMPLE
SELECT COMPANYNAME, ZIPCODE,
             DECODE(ZIPCODE,
             '94103', 'CALIFORNIA',
             '85255', 'ARIZONA',
             'NO STATE') AS STATE
FROM CUSTOMERS;

No comments:

Post a Comment