SQL Flow Field Guide

LEN

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

string transform

What changes

Input
string arguments
Output or change
string or integer
Return type
bigint if expression is of the varchar(max), nvarchar(max), or varbinary(max) data types; otherwise, int. If you're using SC collations, the returned integer value counts UTF-16 surrogate pairs as a s

Syntax at a glance

LEN ( string_expression )

Work example

Measure text characters when trailing spaces are not part of the count.

Compare with DATALENGTH when padding or bytes matter.

Check your work LEN excludes trailing spaces and counts surrogate pairs as one character under supplementary-character collations.

Practice SQL

Open in SQL Flow
SELECT LEN(N'code  ') AS visible_length;

Open Microsoft Learn for full syntax, permissions, and details for your version.