Introduction

Welcome to Snowflake SnowConvert for SQL Server. Let us be your guide on the road to a successful migration.

This is a deprecated version of the SnowConvert documentation, please visit the official site HERE.

What is SnowConvert for SQL Server?

SnowConvert is a software that understands SQL Server scripts and converts this source code into functionally equivalent Snowflake code.

Conversion Types

Specifically, SnowConvert for SQL Server performs the following conversions:

SQL Server to Snowflake SQL

SnowConvert understands the SQL Server source code and converts the Data Definition Language (DDL), Data Manipulation Language (DML), and functions in the source code to the corresponding SQL in the target: Snowflake.

Sample code

SQL Server basic input code:

CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);

Snowflake SQL output code:

CREATE OR REPLACE TABLE PUBLIC.Persons (
    PersonID INT,
    LastName VARCHAR(255),
    FirstName VARCHAR(255),
    Address VARCHAR(255),
    City VARCHAR(255)
);

As you can see, most of the structure remains the same. There are some cases where the datatypes have to be transformed, for example.

SQL Server Stored Procedures to JavaScript Embedded in Snowflake SQL

SnowConvert takes SQL Server stored procedures and converts them to JavaScript embedded into Snowflake SQL. SQL Server's CREATE PROCEDURE is replaced by Snowflake's CREATE OR REPLACE PROCEDURE. JavaScript is called as a scripting language, and all of the inner statements are converted to JavaScript.

Sample code

SQL Server basic stored procedure:

CREATE PROCEDURE SelectAllCustomers
AS
SELECT * FROM Customers
GO;

Snowflake SQL output code, with embedded JavaScript:

CREATE OR REPLACE PROCEDURE SelectAllCustomers ()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
   // REGION SnowConvert Helpers Code
   var _RS, ROW_COUNT, _ROWS, MESSAGE_TEXT, SQLCODE = 0, SQLSTATE = '00000', ERROR_HANDLERS, NUM_ROWS_AFFECTED, PROC_NAME = arguments.callee.name;
   var formatDate = (arg) => (new Date(arg - (arg.getTimezoneOffset() * 60000))).toISOString().slice(0,-1);
   var fixBind = function (arg) {
      arg = arg == undefined ? null : arg instanceof Date ? formatDate(arg) : arg;
      return arg;
   };
   var EXEC = (stmt,binds = [],noCatch = false) => {
      binds = binds ? binds.map(fixBind) : binds;
      for(var stmt of stmt.split(";").filter((_) => _)) {
         try {
            _RS = snowflake.createStatement({
                  sqlText : stmt,
                  binds : binds
               });
            _ROWS = _RS.execute();
            ROW_COUNT = _RS.getRowCount();
            NUM_ROWS_AFFECTED = _RS.getNumRowsAffected();
            return {
               THEN : (action) => !SQLCODE && action(fetch(_ROWS))
            };
         } catch(error) {
            let rStack = new RegExp('At .*, line (\\d+) position (\\d+)');
            let stackLine = error.stackTraceTxt.match(rStack) || [0,-1];
            MESSAGE_TEXT = error.message.toString();
            SQLCODE = error.code.toString();
            SQLSTATE = error.state.toString();
            snowflake.execute({
               sqlText : `SELECT UPDATE_ERROR_VARS(?,?,?,?,?)`,
               binds : [stackLine[1],SQLCODE,SQLSTATE,MESSAGE_TEXT,PROC_NAME]
            });
            throw error;
         }
      }
   };
   // END REGION

   EXEC(`SELECT * FROM PUBLIC.Customers`);
$$;
-- ** MSC-WARNING - MSCEWI1040 - THE STATEMENT IS NOT SUPPORTED IN SNOWFLAKE **
--GO

-- ** MSC-WARNING - MSCEWI1040 - THE STATEMENT IS NOT SUPPORTED IN SNOWFLAKE **
--;
  • When creating the JavaScript code, there is a portion of code added as a helper, required for an easier transformation of the contents of the procedure.

  • You can expect to see warnings with an associated code to help you find out what is happening in the converted code. (See issues and troubleshooting)

SnowConvert Terminology

Before we get lost in the magic of these code conversions, here are a few terms/definitions so you know what we mean when we start dropping them all over the documentation:

  • SQL (Structured Query Language): the standard language for storing, manipulating, and retrieving data in most modern database architectures.

  • SnowConvert: the software that converts securely and automatically your SQL Server files to the Snowflake cloud data platform.

  • Conversion rule or transformation rule: rules that allow SnowConvert to convert from a portion of source code to the expected target code.

  • Parse: parse or parsing is an initial process done by SnowConvert to understand the source code and build up an internal data structure required for executing the conversion rules.

On the next few pages, you'll learn more about the kind of conversions that SnowConvert for SQL Server is capable of. If you're ready to get started, visit the Getting Started page in this documentation.

Last updated