SQL LEN Function

Monday, December 12, 2011

tags SQL

The LEN function returns the length of the value in a text field.

Employees Table

employeeIDemployeeNameage
1000John Smith40
1001Fred White27
1002Jane Scott53
1003Samuel Williams31


In this example, we want to find to number of characters in each of the employees' names.


Syntax

SELECT LEN(column_name)
FROM Table


Example
SELECT LEN(employeeName) as [Length of Name]
FROM employees


Results

Length of Name
10
10
10
15

The SQL LEN function is used to determine the legth of the text in a field.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

SQL Cookbook Head First SQL: Your Brain on SQL A Learners Guide