SQL Server LEN() Function (2024)

Example

Return the length of a string:

SELECT LEN('W3Schools.com');

Try it Yourself »

Definition and Usage

The LEN() function returns the length of a string.

Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length.

Tip: Also look at the DATALENGTH() function.

Syntax

LEN(string)

Parameter Values

Parameter Description
string Required. The string to return the length for. If string is NULL, it returns NULL

Technical Details

Works in: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse

More Examples

Example

Return the length of a string (counts leading spaces, but not trailing spaces):

SELECT LEN(' W3Schools.com ');

Try it Yourself »

Example

Return the length of a string:

SELECT LEN('2017-08');

Try it Yourself »


W3schools Pathfinder

Track your progress - it's free!

SQL Server LEN() Function (2024)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 5746

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.