LEN (Transact-SQL)

Returns the number of characters of the specified string expression, excluding trailing blanks.

Syntax

LEN ( string_expression )

Parameters

ParameterDescription
string_expression Is an expression of any character data type. The expression can be a column, variable, literal, or a return value of an expression. If the expression is NULL, the return value is NULL.

Return Type

Returns int. The return type is int regardless of the argument type.

Remarks

Examples

SELECT LEN('Hello World') AS Length;  -- Returns 11
SELECT LEN('Hello    ') AS Length;    -- Returns 5 (trailing blanks ignored)
SELECT LEN(NULL) AS Length;           -- Returns NULL

See Also