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: The LEN() function does not include trailing spaces at the end of the string when calculating the length. However, the LEN() function DOES count leading spaces at the start of the string when calculating the length.

Tip: Also see the DATALENGTH() function.

Syntax

LEN(string)

Parameter Values

Parameter Description
string Required. The string to return the length for. If string is NULL, LEN() will return NULL

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

Return the length of a string (counts leading spaces as well, 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