Important Points About SQL Server LEN Function

  • The LEN() function returns the number of characters in a given string expression, excluding any trailing spaces.
  • It returns an INT data type, except for VARCHAR(max), NVARCHAR(max), or VARBINARY(max) which returns BIGINT.
  • It includes Leading spaces in the length calculation, but not trailing spaces.
  • If the input string is NULL, LEN() will return NULL.
  • To include trailing spaces in the length calculation, use the DATALENGTH() function instead.

SQL Server LEN() Function

SQL SERVER LEN() function calculates the number of characters of an input string, excluding the trailing spaces.

Similar Reads

LEN() Function in SQL Server

The LEN function in the SQL Server fetches the number of characters in a string. It counts the preceding spaces but not the trailing spaces....

Syntax

LEN(input_string)...

SQL Server LEN Function Examples

Let’s look at some examples of the LEN function in SQL Sever and understand it works....

Important Points About SQL Server LEN Function

The LEN() function returns the number of characters in a given string expression, excluding any trailing spaces. It returns an INT data type, except for VARCHAR(max), NVARCHAR(max), or VARBINARY(max) which returns BIGINT. It includes Leading spaces in the length calculation, but not trailing spaces. If the input string is NULL, LEN() will return NULL. To include trailing spaces in the length calculation, use the DATALENGTH() function instead....

Contact Us