MSDN

MSDN Documentation

LEN (Transact-SQL)

The LEN function returns the number of characters of the specified string expression, excluding trailing blanks.

Syntax

LEN ( string_expression )

Arguments

ParameterTypeDescription
string_expressionnvarchar, varchar, nchar, char, binary, varbinary, or textThe string expression to be evaluated. If the expression evaluates to NULL, LEN returns NULL.

Return Types

Returns int. If string_expression is NULL, the function returns NULL.

Remarks

Examples

SELECT LEN('Hello') AS Length1;               -- Returns 5
SELECT LEN('Hello   ') AS Length2;            -- Returns 5 (trailing blanks omitted)
SELECT LEN(NULL) AS Length3;                  -- Returns NULL
SELECT LEN(CAST(N'Unicode' AS nvarchar(20))) AS Length4; -- Returns 7

Related Functions