Case when else if
- teradata case when in select
- teradata case statement in select
- teradata case when in list
- teradata case example
Teradata case statement in where clause
Teradata case when multiple conditions!
Teradata - CASE and COALESCE
This chapter explains the CASE and COALESCE functions of Teradata.
CASE Expression
CASE expression evaluates each row against a condition or WHEN clause and returns the result of the first match.
If there are no matches then the result from ELSE part of returned.
Syntax
Following is the syntax of the CASE expression.
CASE <expression> WHEN <expression> THEN result-1 WHEN <expression> THEN result-2 ELSE Result-n ENDExample
Consider the following Employee table.
EmployeeNo | FirstName | LastName | JoinedDate | DepartmentNo | BirthDate |
---|---|---|---|---|---|
101 | Mike | James | 3/27/2005 | 1 | 1/5/1980 |
102 | Robert | Williams | 4/25/2007 | 2 | 3/5/1983 |
103 | Peter | Paul | 3/21/2007 | 2 | 4/1/1983 |
104 | Alex | Stuart | 2/1/2008 | 2 | 11/6/1984 |
105 | Robert | James | 1/4/2008 | 3 | 12/1/1984 |
The following example evaluates the DepartmentNo column and returns value of 1 if the department number is 1; returns 2 if the department number is 3; otherwise it returns value as invalid department.
SELECT EmployeeNo, CASE DepartmentNo WHEN 1 THEN 'Admin' WHEN 2 THE- teradata month difference
- teradata select case when else