Monday, 16 February 2015

How to write best CASE example in Teradata SQL

Teradata SQL
Teradata Case Statement
What is CASE statement?


  • CASE will provide logical control of the SQL. In CASE statement we can give >,<,=,<>
  • The CASE has structure it starts with CASE and end with END


See an example of Advanced CASE:

SELECT
  COMPANY,
  CASE
    WHEN DEPT_NO = 1 THEN 'HR'
    WHEN DEPT_NO = 2 THEN 'IT'
    WHEN DEPT_NO = 3 THEN 'FINANCE'
    ELSE 'I DON''T KNOW'
  END AS DEPT_NAME
FROM SAMPLES.COMP_DETL
ORDER BY 1;

The above query covered all like ELSE, THEN, WHEN, CASE and END. This is the best example how typically,you can write CASE in an SQL query for logical validation.

No comments:

Post a Comment

5 Top Teradata DATE functions read now

  The following are the list of DATE functions. These are very frequently being used in Teradata. Current DATE The following statem...