The LEN function returns the number of characters in a string.
LEN does not count trailing spaces (unlike DATALENGTH).
LEN returns NULL if the input string is NULL.
This example returns the the number of characters in the input string.
SELECT LEN('Structured Query Language') AS Length
| Length |
|---|
| 25 |
Syntax of the LEN function.
LEN(string)
string -- a string expression, variable, or column name.
| PRODUCT |
|---|
| Id |
| ProductName |
| SupplierId |
| UnitPrice |
| Package |
| IsDiscontinued |
SELECT ProductName,
LEN(ProductName) AS Length
FROM Product
| ProductName | Length |
|---|---|
| Alice Mutton | 12 |
| Aniseed Syrup | 13 |
| Boston Crab Meat | 16 |
| Camembert Pierrot | 17 |
| Carnarvon Tigers | 16 |
![]() |
|