SQL Server LEN in Snowflake, Databricks and BigQuery
Snowflake and Databricks accept LEN, and BigQuery uses LENGTH. All three count trailing spaces, while SQL Server LEN ignores them, so lengths can differ after migration.
SQL Server function: LEN(string_expression) · SQL Server docs
Equivalents
| Target | Support | Syntax | Notes | Source |
|---|---|---|---|---|
| Snowflake | Same name | LEN(expression) | Alias of LENGTH. Counts characters, including trailing spaces. | Snowflake docs |
| Databricks | Same name | len(expr) | Synonym of char_length (Databricks Runtime 11.3 LTS and above). Counts trailing spaces. | Databricks docs |
| BigQuery | Different name | LENGTH(value) | Counts characters for STRING and bytes for BYTES. | BigQuery docs |
Behavior differences to check
- 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.
Examples
Find codes longer than 10 characters
SELECT code FROM products WHERE LEN(code) > 10;SELECT code FROM products WHERE LEN(RTRIM(code)) > 10;SELECT code FROM products WHERE len(rtrim(code)) > 10;SELECT code FROM products WHERE LENGTH(RTRIM(code)) > 10;