Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

LEN Function

Posted By: Sarita Patel     Category: SQL Server     Views: 3887

This article explains LEN function of sql server with examples.

LEN is used to get number of characters in a specified string.


Syntax of LEN Function :

LEN (string_expression)

string_expression is a string to get length of it.

Return type of it is an integer value.


Examples of LEN Function :

Example 1 : Use of LEN function in select clause

SELECT LEN('Syntax-Example')

Output
14

Above example returns number of characters in the specified string i.e. 14



Example 2 : Use of LEN function to display field length of table in a select clause


SELECT ContactName, LEN(ContactName) AS Length
FROM    Customers

Output
ContactName           Length
Maria Anders            12
Ana Trujillo               12
Antonio Moreno        14
Thomas Hardy          12
Christina Berglund    18
Hanna Moos             10

Above example displays length of customer name in customer table.



Example 3 : Use of LEN function in where clause


SELECT ProductName
FROM    Products
WHERE  LEN(ProductName)  <  20

Output
ProductName
Chai
Chang
Aniseed Syrup
Mishi Kobe Niku
Ikura
Queso Cabrales

Above example displays all customer name having length less than 20 characters.
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on LEN Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of LEN Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!