SnowConvert AI - SQL Server-Azure Synapse - General Language Elements¶
In this section you could find information about general statements of Transact-SQL.
COLLATE¶
Applies to
SQL Server
Azure Synapse Analytics
The transformation of the collate depends on its value, since it can be supported or not supported.
Currently, these are the languages that are supported for the transformation, if they are found in the collate, they will be transformed into its Snowflake equivalent.
SQL Server |
Snowflake |
|---|---|
Latin1_General |
EN |
Modern_Spanish |
ES |
French |
FR |
If the language is not one of the above, the collate will be commented.
The collate in SQL Server comes with additional specifications, such as CI, CS, AI, and AS. If there are additional specifications that are unsupported, they will be commented in the result.
Source¶
Expected¶
Let’s see an example of collate in a Create Table
Source¶
Expected¶
As you can see, the transformation of Collate inside a Select or a Table is the same.
COMPUTED COLUMN¶
The computed expression could not be transformed.
Applies to
SQL Server
Azure Synapse Analytics
Description¶
The expression of a computed column could not be transformed.
Code Example¶
Input Code:¶
Output Code:¶
Recommendations¶
Add manual changes to the not-transformed expression.
If you need more support, you can email us at snowconvert-support@snowflake.com
Related EWIs¶
SSC-FDM-TS0014: Computed column transformed.
OUTER APPLY¶
Outer apply statement equivalence translation.
Applies to
SQL Server
Azure Synapse Analytics
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
When OUTER APPLY is specified, one row is produced for each row of the left rowset even when the right-side rowset expression returns an empty rowset for that row. (OUTER APPLY Definition)
Syntax¶
Snowflake equivalence¶
Despite the unsupported statement OUTER APPLY in Snowflake, there is an equivalent statement, which is LATERAL. Hence, the translation for the statement is conducted to get the same functionality through the use of alternative solutions.
Nevertheless, the LATERAL statement in Snowflake has two variations in syntax. In fact, the INNER JOIN LATERAL variation is used in this specific translation.
The INNER JOIN LATERAL grammar from Snowflake is the following:
Note
<inline_view> must not be a table name.
And, the single LATERAL statement is shown below:
Sample source¶
The following example shows a general translation between OUTER APPLY and INNER JOIN LATERAL:
SQL Server¶
Output¶
p.ProjectName |
e.ProjectName |
FirstName |
|---|---|---|
Project A |
Project A |
John |
Project A |
Project A |
Jane |
Project A |
Project B |
Michael |
Project B |
Project A |
John |
Project B |
Project A |
Jane |
Project B |
Project B |
Michael |
Project C |
Project A |
John |
Project C |
Project A |
Jane |
Project C |
Project B |
Michael |
Snowflake¶
Output¶
PROJECTNAME |
PROJECTNAME_2 |
FIRSTNAME |
|---|---|---|
Project A |
Project A |
John |
Project A |
Project A |
Jane |
Project A |
Project B |
Michael |
Project B |
Project A |
John |
Project B |
Project A |
Jane |
Project B |
Project B |
Michael |
Project C |
Project A |
John |
Project C |
Project A |
Jane |
Project C |
Project B |
Michael |
Known issues¶
Since the translation is an equivalence from the input, there are some limitations.
TOP and WHERE statements may be reviewed for optimal behavior.
A correlation name at the end of the statement may be needed. In Snowflake, the query does not represent a problem if the correlation name is not in the query, but functionality may change and does not form part of the accepted pattern in SQL Server.
SQL Server¶
Translation output¶
Specific statements that are not supported may comment out all the block code (example taken from: JSON Example).
SQL Server¶
Translation output¶
Related EWIs¶
No related EWIs.
USE¶
Transact-SQL USE statement Snowflake equivalence.
Applies to
SQL Server
The USE statement has its own equivalent in Snowflake. The statement will be translated to the USE DATABASE statement in Snowflake.
Translation Examples¶
Source¶
Output¶
Database name¶
The database name specified in the USE statement, could have a change if it comes inside Square Brackets ([ ]). The first bracket and the last bracket will be replaced with quotes. Example:
Source¶
Output¶
User Defined Database¶
If a user specifies to the Conversion Tool a custom database name to be applied to all the objects by using the -d parameter, and wants the USE statements to be transformed, the Database name should be applied just to the USE statement and not to the objects. This will override the specified database from the use statement. Example:
Source¶
Output¶
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
EXECUTE¶
Applies to
SQL Server
Azure Synapse Analytics
The translation for Exec or Execute Statements is not supported in Snowflake, but it will be translated to CALL statement.
Note
Some parts in the output code are omitted for clarity reasons.
Input¶
Output¶
For more information about Execute visit: Execute inside Procedures
PRINT¶
Applies to
SQL Server
Azure Synapse Analytics
The Print statement is not directly supported in Snowflake, but it will be translated to its closest equivalent, the SYSTEM$LOG_INFO built-in function.
Input¶
Output (Inside SnowScript)¶
Output (Outside of SnowScript)¶
When the Print statement is used outside of a stored procedure, it is required to be called from a SnowConvert AI UDP.
Before you can begin logging messages, you must set up an event table. For more information, see: Logging messages in Snowflake Scripting
System Stored Procedures¶
SP_EXECUTESQL¶
Translation specification for the system procedure SP_EXECUTESQL.
Applies to
SQL Server
Azure Synapse Analytics
Description¶
The SP_EXECUTESQL system stored procedure is used to execute a Transact-SQL statement or batch that can be reused many times, or one that is built dynamically. The statement or batch can contain embedded parameters.
This functionality can be emulated in Snowflake through the EXECUTE IMMEDIATE statement and with a user-defined function (UDF) for embedded parameters.
For more information about the user-defined function (UDF) used for this translation, check TRANSFORM_SP_EXECUTE_SQL_STRING_UDF(STRING, STRING, ARRAY, ARRAY).
Syntax¶
Transact¶
Sample Source Patterns¶
All patterns will transform SP_EXECUTESQL into Snowflake’s EXECUTE IMMEDIATE statement and only modify the SQL string to be executed when using embedded parameters.
Warning
SSC-EWI-0030 (Usage of Dynamic SQL) will be added for all patterns. Even though the translation for SP_EXECUTESQL is equivalent to Snowflake, in this context, this EWI indicates that the SQL string might require manual fixes for the translation to execute as intended.
Setup Data¶
Transact¶
Snowflake¶
Without embedded parameters¶
When no embedded parameters are being used, the SP_EXECUTESQL is transformed into an EXECUTE IMMEDIATE statement and use the SQL string without modifications.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
Snowflake¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
With embedded parameters for data binding¶
For embedded parameters for data binding, the SP_EXECUTESQL is transformed into an EXECUTE IMMEDIATE statement, and the SQL string is modified through the TRANSFORM_SP_EXECUTE_SQL_STRING_UDF.
The result of the EXECUTE IMMEDIATE is assigned to the ProcedureResultSet variable and later returned as TABLE(ProcedureResultSet).
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Doe |
2 |
21 |
Snowflake¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Doe |
2 |
21 |
With embedded OUTPUT parameters¶
For embedded OUTPUT parameters, the SP_EXECUTESQL is transformed into an EXECUTE IMMEDIATE statement, and the SQL string is modified through the TRANSFORM_SP_EXECUTE_SQL_STRING_UDF.
Additionally, a SELECT $1, ..., $n INTO :outputParam1, ..., :outputParamN FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())) is added to the result of each column to the corresponding OUTPUT parameter.
Warning
SSC-FDM-TS0028 is added to the SELECT INTO statement. It is essential for the parameters in the INTO clause to appear in the same order as they were assigned in the original SQL String.
Otherwise, manual changes are required to meet this requirement.
Transact¶
Results¶
<anonymous> |
|---|
32 |
Snowflake¶
Results¶
:MAXAGE::NUMBER(38,0) |
|---|
32 |
With both embedded OUTPUT parameters and data binding¶
The translation is the same as for only OUTPUT parameters.
Transact¶
Results¶
<anonymous> |
<anonymous> |
|---|---|
24 |
4 |
Snowflake¶
Results¶
:MAXAGE::NUMBER(38,0) |
:MAXID::NUMBER(38,0) |
|---|---|
24 |
4 |
Parameters not in order of definition¶
This pattern follows the same rules as the previous patterns. TRANSFORM_SP_EXECUTE_SQL_STRING_UDF replaces the parameter values in the correct order.
Transact¶
Results¶
<anonymous> |
<anonymous> |
|---|---|
24 |
4 |
<anonymous> |
<anonymous> |
|---|---|
24 |
4 |
Snowflake¶
Results¶
:MAXAGE::NUMBER(38,0) |
:MAXID::NUMBER(38,0) |
|---|---|
24 |
4 |
:MAXAGE::NUMBER(38,0) |
:MAXID::NUMBER(38,0) |
|---|---|
24 |
4 |
Execute direct values¶
This translation also handles the cases where the values are directly assigned instead of using variables.
Transact¶
Results¶
<anonymous> |
<anonymous> |
|---|---|
24 |
4 |
Snowflake¶
Results¶
:MAXAGE::NUMBER(38,0) |
:MAXID::NUMBER(38,0) |
|---|---|
24 |
4 |
SQL string dynamically built¶
This pattern follows the same rules as the previous patterns. However, assigning the result of the EXECUTE IMMEDIATE statement might not be added if the SQL string is not a simple single query with or without embedded parameters.
Furthermore, the SQL string must start with the literal value 'SELECT' for SnowConvert AI to correctly identify that a SELECT statement is going to be executed.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Doe |
2 |
21 |
Snowflake¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Doe |
2 |
21 |
Returning multiple result sets¶
Snowflake Scripting procedures only allow one result set to be returned per procedure.
To replicate Transact-SQL behavior, when two or more result sets are to be returned, they are stored in temporary tables. The Snowflake Scripting procedure will return an array containing the names of the temporary tables. For more information, check SSC-FDM-0020.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Doe |
2 |
21 |
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
INSERT FIRST |
1200 |
230 |
Snowflake¶
Results¶
WITH_MULTIPLE_RETURNS |
|---|
[ “RESULTSET_88C35D7A_1E5B_455D_97A4_247806E583A5”, “RESULTSET_B2345B61_A015_43CB_BA11_6D3E013EF262” ] |
Known Issues¶
1. Invalid code is detected¶
SP_EXECUTESQL can execute more than one SQL statement inside the SQL string. Snowflake also supports executing multiple SQL statements, but need to be enclosed in a BEGIN ... END block.
Furthermore, when executing multiple statements from a BEGIN ... END block, the EXECUTE IMMEDIATE will not return a resultset.
The translation for these cases is not yet supported by SnowConvert AI.
For more information, check SSC-EWI-0030.
Thus, when this case is detected, in the translated code, the EXECUTE IMMEDIATE will not be assigned to the ProcedureResultSet.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
INSERT FIRST |
1200 |
230 |
Snowflake¶
Results¶
2. Valid or Invalid code is not detected¶
When the SQL string is built dynamically through concatenations, SnowConvert AI might not detect what statement is going to be executed. Thus, in the translated code, the EXECUTE IMMEDIATE will not be assigned to the ProcedureResultSet.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
INSERT FIRST |
1200 |
230 |
Snowflake¶
Results¶
3. Invalid code is mistaken as valid¶
If the SQL string starts with a SELECT statement and is followed by more statements, SnowConvert AI will detect this as a valid code and try to assign the result of the EXECUTE IMMEDIATE to the ProcedureResultSet. This leads to a compilation error.
For more information, check SSC-EWI-0030.
Transact¶
Results¶
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
Name |
ID |
AGE |
|---|---|---|
John Smith |
1 |
24 |
John Doe |
2 |
21 |
Mary Keller |
3 |
32 |
Mundane Man |
4 |
18 |
Snowflake¶
Results¶
Related EWIs¶
SSC-EWI-0030: The statement below has usages of dynamic SQL
SSC-FDM-TS0028: Output parameters must have the same order as they appear in the executed code.
SSC-FDM-0020: Multiple result sets are returned in temporary tables.
SP_RENAME¶
Stored Procedure to Rename certain objects in SQL Server
Applies to
SQL Server
Azure Synapse Analytics
The SP_RENAME system store procedure can be emulated in Snowflake in certain scenarios. In general, the equivalent is the EXECUTE IMMEDIATE using a dynamic statement with the ALTER TABLE and the original parameters.
Translation Examples for Tables¶
Source¶
Output¶
Source¶
Output¶
Translation Examples for Columns¶
Source¶
Output¶
Source¶
Output¶
Related EWIs¶
SSC-EWI-TS0075: Translation for Built-In Procedure Is Not Currently Supported.