CASE (Snowflake Scripting)¶
A CASE statement provides a way to specify multiple conditions.
For more information on branching constructs, see Working with conditional logic.
Note
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
Syntax¶
Simple CASE statement:
Where:
expression_to_matchThe expression to match.
expressionIf the value of this expression matches the value of
expression_to_match, then the statements in this clause are executed.
Searched CASE statement:
Where:
boolean_expressionIf this expression evaluates to TRUE, then the statements in this clause are executed.
Usage notes¶
- If more than one branch of the
CASEwould match the expression, only the first is used. - When you compare expressions, NULL does not match NULL. If you wish to test explicitly for NULL values, use IS [ NOT ] NULL.
Examples¶
This example demonstrates a simple CASE statement:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_streamorexecute_stringmethod in Python Connector code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):
When you call this stored procedure, the procedure produces the following output:
This example demonstrates a searched CASE statement:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_streamorexecute_stringmethod in Python Connector code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):
When you call this stored procedure, the procedure produces the following output: