Retrieve the number of characters in a given string.
SELECT LEN(‘W3Schools.com’); |
The LEN() function returns the number of characters in a string.
Note that trailing spaces at the end of the string are not counted, but leading spaces at the beginning of the string are included in the length calculation.
Tip: Also consider using the DATALENGTH() function for counting the number of bytes used to store an expression in SQL.
LEN(string) |
Parameter |
Description |
string |
Mandatory. Specifies the string for which the length is returned. If the string is NULL, the function returns NULL. |
Works in: |
SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve the length of a string, including leading spaces but excluding trailing spaces.
SELECT LEN(‘ W3Schools.com ‘); |
Retrieve the number of characters in a string.
SELECT LEN(‘2017-08’); |