Sql Server Len Function

SQL Server: LEN Function

In this post explains how to use the LEN function in SQL Server (Transact-SQL) with syntax and examples.

Description

In SQL Server (Transact-SQL), the LEN function returns the length of the specified string. It is important to note that the LEN function does not include trailing space characters at the end the string when calculating the length.

Syntax

The syntax for the LEN function in SQL Server (Transact-SQL) is:

LEN( string )

Parameters or Arguments

string

The string to return the length for.

Note

Example

Let's look at some SQL Server LEN function examples and explore how to use the LEN function in SQL Server (Transact-SQL).

For example:

SELECT LEN('AODBA.com');
Output: 16

SELECT LEN('AODBA.com   ');
Output: 16  <strong>       (trailing spaces are not included in the calculation)

SELECT LEN('   AODBA.com');
Output: 19

SELECT LEN('   AODBA.com   ');
Output: 19   <strong>      (trailing spaces are not included in the calculation)

SELECT LEN(' ');
Output: 0    <strong>      (trailing spaces are not included in the calculation)

SELECT LEN('');
Output: 0

SELECT LEN(NULL);
Output: NULL