bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

SQL Server LEN() Function

Concept visual

SQL Server LEN() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Return the length of a string:

Select

LEN('W3Schools.com');

Definition and Usage

The LEN() function returns the length of a string.

Note:

Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length.

Tip:

Also look at the DATALENGTH() function.

Syntax

Len(

string )

Parameter Values

Parameter

Description string

Required. The string to return the length for. If string is NULL, it returns NULL

Technical Details

Works in:

SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse

More Examples

Example

Return the length of a string (counts leading spaces, but not trailing spaces):

Select

LEN(' W3Schools.com ');

Example

Return the length of a string:

Select

LEN('2017-08');

Previous

❮ SQL Server Functions

Next

Previous

SQL Server LEFT() Function

Next

SQL Server LOWER() Function