CASE

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

The CASE statement in Redshift lets you return values based on conditions, enabling conditional logic in queries. It has two forms: simple and searched. (Redshift SQL Language Reference Conditionals: Case).

Simple Case

A simple CASE statement provides conditional execution based on equality of operands.

Grammar Syntax

CASE search-expression
WHEN expression [, expression [ ... ]] THEN
  statements
[ WHEN expression [, expression [ ... ]] THEN
  statements
  ... ]
[ ELSE
  statements ]
END CASE;

Sample Source Patterns

Input Code:

Output Code:

Searched Case

Grammar Syntax

Sample Source Patterns

Input Code:

Output Code:

CASE Without ELSE

In Redshift, when a CASE expression is executed and none of the validated conditions are met, and there is no ELSE defined, the exception 'CASE NOT FOUND' is triggered. In Snowflake, the code executes but returns no result. To maintain the same functionality in Snowflake in this scenario, an exception with the same name will be declared and executed if none of the CASE conditions are met.

Input Code:

Output Code:

Known Issues

There are no known issues.

There are no related EWIs.

Last updated