SQL Server to Snowflake: function mapping
6 of 12 common SQL Server functions need a change in Snowflake. Mapping table with Snowflake syntax and behavior differences.
Other targets: SQL Server to Databricks · SQL Server to BigQuery
Needs a rewrite (2)
No Snowflake function with the same behavior; use the construct shown.
| SQL Server | Snowflake | Notes |
|---|---|---|
| CONVERT | Rewrite CAST(expr AS type) / TO_CHAR(expr, 'YYYYMMDD') | Style 112 (yyyyMMdd) is 'YYYYMMDD', style 23 (yyyy-MM-dd) is 'YYYY-MM-DD', style 120 is 'YYYY-MM-DD HH24:MI:SS'. Style codes only exist in SQL Server. Every CONVERT with a third argument needs a manual rewrite; a search for "CONVERT(" with three arguments finds them. CONVERT(DATE, expr) on strings relies on SQL Server language settings to read the input. In the targets, parse strings with TO_DATE (Snowflake, Databricks) or PARSE_DATE (BigQuery) and an explicit format. |
| EOMONTH | Rewrite LAST_DAY(date_or_time_expr [, date_part]) | Returns a DATE. The optional date_part also gives the last day of a year, quarter or week. EOMONTH(d, n) has no single-function equivalent. Write LAST_DAY(DATEADD(month, n, d)) in Snowflake, last_day(add_months(d, n)) in Databricks and LAST_DAY(DATE_ADD(d, INTERVAL n MONTH)) in BigQuery. |
Different name (4)
Same behavior under another name; rename the call and check the notes.
| SQL Server | Snowflake | Notes |
|---|---|---|
| IIF | Different name IFF(condition, expr1, expr2) | Returns expr2 when the condition is FALSE or NULL. A NULL condition returns the false branch in all three targets, the same as SQL Server. Nested IIF calls translate one to one, but a CASE expression is easier to read when there are more than two branches. |
| ISNULL | Different name IFNULL(expr1, expr2) | NVL(expr1, expr2) is the same function. COALESCE also works and accepts more than two arguments. Return type: SQL Server returns the type of the first argument and may truncate the replacement, for example ISNULL(CAST(NULL AS VARCHAR(2)), 'abc') returns 'ab'. The target functions return a common type of both arguments, so results that relied on truncation change. |
| STRING_AGG | Different name LISTAGG([DISTINCT] expr [, delimiter]) [WITHIN GROUP (ORDER BY ...)] | Ignores NULL values. The default delimiter is an empty string. The separator is optional in the targets and defaults to an empty string, while SQL Server requires it. Keep it explicit to avoid values running together. SQL Server returns an error when the result exceeds 8,000 bytes for VARCHAR input unless the input is cast to VARCHAR(MAX). The targets have their own size limits but no such cast is needed. |
| STUFF | Different name INSERT(base_expr, pos, len, insert_expr) | Same argument order as STUFF. Returns NULL if any argument is NULL. The common pattern STUFF((SELECT ',' + name FROM ... FOR XML PATH('')), 1, 1, '') only removes the leading comma of an XML-built list. Replace the whole expression with LISTAGG (Snowflake), string_agg or listagg (Databricks) or STRING_AGG (BigQuery). See STRING_AGG. SQL Server STUFF returns NULL when start is larger than the string length. Check how each target handles positions past the end before relying on it. |
Works as written (6)
The same call runs, but check the notes for behavior differences.
| SQL Server | Snowflake | Notes |
|---|---|---|
| CHARINDEX | Same name CHARINDEX(expr1, expr2 [, start_pos]) | Same argument order; returns 0 when not found. POSITION is an alias. SQL Server comparisons follow the column collation, which is often case-insensitive. The targets compare case-sensitively by default, so CHARINDEX('abc', 'ABC') stops matching. |
| DATEADD | Same name DATEADD(date_or_time_part, value, date_or_time_expr) | Same argument order. Also accepts abbreviations such as dd and mm. Month arithmetic at month end: SQL Server returns the last day of the target month when the day does not exist (Jan 31 + 1 month = Feb 28 or 29). Snowflake DATEADD, Databricks and BigQuery behave the same way for this case. |
| DATEDIFF | Same name DATEDIFF(date_or_time_part, expr1, expr2) | Same argument order and the same boundary counting as SQL Server: DATEDIFF(year, '2024-12-31', '2025-01-01') returns 1. |
| GETDATE | Same name GETDATE() | Alias of CURRENT_TIMESTAMP. Returns TIMESTAMP_LTZ in the session time zone (TIMEZONE parameter). Parentheses are required. SQL Server GETDATE returns the local time of the database server as DATETIME with no time zone. Cloud warehouses default to UTC or the session time zone, so day boundaries and "today" filters can shift by several hours. Set the session time zone or pass one explicitly. |
| LEN | Same name LEN(expression) | Alias of LENGTH. Counts characters, including trailing spaces. SQL Server LEN('abc ') returns 3; the targets return 5. Wrap the argument in RTRIM to keep the old result, for example LENGTH(RTRIM(col)). Columns migrated from CHAR(n) may arrive padded with spaces, which makes the difference more common than expected. |
| TOP | Same name SELECT TOP n ... | TOP n and LIMIT n are equivalent in Snowflake. TOP n PERCENT and TOP n WITH TIES need a rewrite with window functions, for example QUALIFY RANK() OVER (ORDER BY score DESC) <= n for WITH TIES (QUALIFY works in all three targets). TOP in UPDATE and DELETE statements is SQL Server only; rewrite those with a key filter. |