DECLARE
Translation reference to convert SQL Server DECLARE statement to Snowflake Scripting
Description
Transact-SQL DECLARE statement allows the creation of variables that can be used in the scope of the batch or a stored procedure. For more information regarding SQL Server DECLARE, check here.
Sample Source Patterns
Declare variables
Variables can be created in different ways. Variables may or may not have a default value and several variables can be declared in the same line.
Notice that Snowflake Scripting does not allow to create more than one variable per line.
SQL Server
Snowflake Scripting
Declare table variables
SQL Server allows the creation of table variables that can be used as regular tables. Snowflake scripting does not support this, instead, a table can be created and then dropped at the end of the procedure.
SQL Server
Snowflake Scripting
DECLARE statement outside routines (functions and procedures)
Unlike SQL Server, Snowflake does not support executing isolated statements like DECLARE outside routines like functions or procedures. For this scenario, the statement should be encapsulated in an anonymous block, as shown in the following examples. This statement is usually used before a SET STATEMENT
.
SQL Server
Snowflake Scripting
If there is a scenario with only DECLARE statements, the BEGIN...END block should have a RETURN NULL statement to avoid errors, since this block can't be empty.
SQL Server
Snowflake Scripting
Known Issues
No issues were found.
Related EWIs
No related EWIs.
Last updated