SET

Translation reference to convert Transact-SQL SET statement to Snowflake

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.

Applies to

Description

Sets the specified local variable, previously created by using the DECLARE @local_variable statement, to the specified value. For more information for Transact-SQL SET, check here.

There are four SET cases that are the following:

SET   
{ @local_variable  
    [ . { property_name | field_name } ] = { expression | udt_name { . | :: } method_name }  
}  
|  
{ @SQLCLR_local_variable.mutator_method  
}  
|  
{ @local_variable  
    {+= | -= | *= | /= | %= | &= | ^= | |= } expression  
}  
|   
  { @cursor_variable =   
    { @cursor_variable | cursor_name   
    | { CURSOR [ FORWARD_ONLY | SCROLL ]   
        [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]   
        [ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]   
        [ TYPE_WARNING ]   
    FOR select_statement   
        [ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } ]   
      }   
    }  
}

Sample Source Patterns

Transact-SQL

Snowflake Scripting

SET statement outside routines (functions and procedures)

Unlike Transact-SQL, Snowflake does not support executing isolated statements like SET 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 after a DECLARE STATEMENT.

Transact-SQL

Snowflake Scripting

If there is a scenario with only SET statements, the DECLARE block is not necessary. Probably this scenario will produce runtime errors if there is an attempt of setting a value to a variable that is not declared.

Transact-SQL

Snowflake Scripting

Known Issues

1. SET of a local variable with property name

This type of set is not currently supported by Snowflake scripting.

2. SET of a local variable with mutator method

This type of set is not currently supported by Snowflake scripting.

  1. SSC-EWI-TS0037: Snowflake Scripting Cursors are non-scrollable.

  2. SSC-EWI-0073: Pending Functional Equivalence Review.

  3. SSC-FDM-TS0013: Snowflake Scripting cursor rows are not modifiable.

Last updated