LEN (TSQL Function)

Returns the length of a string, excluding trailing blanks.

Syntax

LEN ( string_expression )

Arguments

string_expression
is a string expression of type varchar.

Return Types

Returns int.

Remarks

This function excludes trailing blanks.

The similar function CHARLEN returns the full length of the string.

Examples

PRINT LEN('guépard');
PRINT CHARLEN('guépard');
PRINT LEN('guépard      ');     -- trailing blanks are excluded
PRINT CHARLEN('guépard      '); -- trailing blanks are not excluded
PRINT LEN('');
PRINT CHARLEN('');

The result is:

7
7
7    <--- LEN() excludes trailing blanks
13
0
0