SQL Server LEN() Function
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 »