Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

SQL LEN Function

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.

Example

#

This example returns the the number of characters in the input string.

SELECT LEN('Structured Query Language') AS Length
Result:  1 record
Length
25

Syntax

Syntax of the LEN function.

LEN(string)

string -- a string expression, variable, or column name.


More Examples

LEN of a column

PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
Problem: List all products with the length of the product names.
SELECT ProductName, 
       LEN(ProductName) AS Length
  FROM Product
Result:  78 records
ProductName Length
Alice Mutton 12
Aniseed Syrup 13
Boston Crab Meat 16
Camembert Pierrot 17
Carnarvon Tigers 16

You may also like



Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides


vsn 3.1