Book Image

Teradata Cookbook

By : Abhinav Khandelwal, Viswanath Kasi, Rajsekhar Bhamidipati
Book Image

Teradata Cookbook

By: Abhinav Khandelwal, Viswanath Kasi, Rajsekhar Bhamidipati

Overview of this book

Teradata is an enterprise software company that develops and sells its eponymous relational database management system (RDBMS), which is considered to be a leading data warehousing solutions and provides data management solutions for analytics. This book will help you get all the practical information you need for the creation and implementation of your data warehousing solution using Teradata. The book begins with recipes on quickly setting up a development environment so you can work with different types of data structuring and manipulation function. You will tackle all problems related to efficient querying, stored procedure searching, and navigation techniques. Additionally, you’ll master various administrative tasks such as user and security management, workload management, high availability, performance tuning, and monitoring. This book is designed to take you through the best practices of performing the real daily tasks of a Teradata DBA, and will help you tackle any problem you might encounter in the process.
Table of Contents (19 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Using CASE statements


Like any other programming language, Teradata SQL provides if-then-else logic using the CASE statement. It helps in fetching alternate values for a column based on the condition specified in the expression. If any one of the values gets qualified as TRUE, its value gets captured and the counter goes on until all the rows have been processed.

Every CASE statement needs to have a pair of WHEN and THEN statements and to be closed using an END statement. 

The syntax of CASE is as follows:

The syntax of case statement

Let's put this into a code statement as follows:

/*CASE SELECT*/
SELECT EMP_name, Month, 
CASEWHENMONTH = 'JUNE'THEN'yes'ELSENULLENDAS SUMMER
FROM Table_CASE

Let's understand this by means of a flow chart:

Decoding the statement:

  1. The CASE 1 statement checks each row to see if the conditional statement is met.
  2. For any given row for CASE 1, if that conditional statement is true, the counter for the true condition is increased or the corresponding value gets stored. 
  3. In...