CASE Statement in Teradata

Teradata offers "CASE" statement to retrieve/update the results from a column of a table in a different way to promote the end user's understanding.

Syntax: (Applied on column2)
SELECT column1,
CASE column2
WHEN value1 THEN result1
WHEN value2 THEN result2
END
FROM table


The CASE functionality must meet END to operate for a table.

Let us see few forgetcode examples for this,

1. Employees of a company want to know their salary according to their designation.
So, Employees will give the ID and Designation for the query.

Consider, the company is giving salary like below.
DesignationSalary
Software Engineer25000
Senior Engineer35000
Team manager50000

The company can show the results like this with ID and Salary:

SELECT EmpID,
CASE EmpDesignation
WHEN 'Software Engineer' THEN 25000
WHEN 'Senior Engineer' THEN 35000
WHEN 'Team manager' THEN 50000
END
FROM Employee


You can do arithmetic operations also in the CASE.
Same code as above with increments (+ operation)

SELECT EmpID,
CASE EmpDesignation
WHEN 'Software Engineer' THEN 25000+500
WHEN 'Senior Engineer' THEN 35000+1000
WHEN 'Team manager' THEN 50000+2000
END
FROM Employee


Now, you have to show the cities whether they belong to north or south.
Will you write like this ?.. Great

SELECT country,
CASE city
WHEN 'CHENNAI' THEN 'SOUTH INDIA'
WHEN 'DELHI' THEN 'NORTH INDIA'
WHEN 'CHANDIGARH' THEN 'NORTH INDIA'
WHEN 'BANGALORE' THEN 'SOUTH INDIA' 
END
FROM map


If you want to represent a value in different manner, you can do with CASE now !!!


..