THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server LEN() Function

❮ SQL Server Functions

Example

Return the length of a string:

SELECT LEN('W3Schools.com');
Try it Yourself »

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   ');
Try it Yourself »

Example

Return the length of a string:

SELECT LEN('2017-08');
Try it Yourself »

❮ SQL Server Functions