How it works...

As you saw, based on the Connection_type column we were able to classify pre-paid and post-paid customers. Both CASE statements get executed, as can be seen in the result set. You must have noticed that the last customer has a connection type of Not Sure; this is because the Connection_type for this customer is NULL and it was not able to get processed by both the CASE statements. Therefore, it went to the default CASE statement.

This is how we can use CASE statements in Teradata SQL to cater to the function of if-else statements.

A quick review:

  • The CASE statement always has the SELECT clause.
  • CASE must have the following identifiers: WHEN, THEN, and END. ELSE is an optional component.
  • WHERE is used as conditional statement. ...

Get Teradata Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.