SQL Server : Get Length of a String with LEN() Function

The LEN() function is a function that is used to get the length of a string.

Syntax:

LEN(string)

e.g:

SELECT LEN('You need a short vacation.') LenValue

SELECT LEN('Come again tomorrow morning') LenValue


If there is a space at the end of the string it is not included when calculating the length. However, leading spaces at the beginning of the string are included when calculating the length.

SELECT LEN('You need a short vacation. ') LenValue

SELECT LEN(' Come again tomorrow morning') LenValue




Post a Comment

0 Comments