IF
Translation reference to convert SQL Server IF..ELSE clauses to Snowflake Scripting
Last updated
Translation reference to convert SQL Server IF..ELSE clauses to Snowflake Scripting
Last updated
The IF clause allows an SQL statement or a block of statements to be conditionally executed as long as the Boolean expression is true; otherwise, the statements in the optional ELSE clause will be executed. SQL Server also supports embedding multiple IF... ELSE clauses in case multiple conditions are required, or the CASE clause can also be used.
For more information for SQL Server IF...ELSE, check .
Note: To define a statement block, use the control-of-flow keywords BEGIN
and END
.
The following code refers to an IF... ELSE in SQL Server that conditions the variable @value to identify if it is less than 5, if it is between 5 and 10, or if it has any other value. Since @value is initialized as 7, the second condition must be true and the result must be 200.
SQL Server
Snowflake Scripting
No issues were found.
Unlike SQL Server, Snowflake does not support executing isolated statements like IF...ELSE outside routines like functions or procedures. For this scenario, the statement should be encapsulated in an anonymous block, as shown in the following example. You can read more about how to correctly return the output values in the.
: Pending Functional Equivalence Review.
: Multiple result sets are returned in temporary tables.