Use of LEN Function in SQL

Use of LEN Function in SQL:

(1) “LEN” function is used to calculate the length of the string.

(2) Let’s take an example to calculate the length of “The Universe” as shown.

(3) Select the database in the SQL server and click on the “New Query” button as shown.

Select the database in the SQL server and click on the new query button

(4) After that new query editor opens as shown.

new query editor open in sql

(5) After doing the above steps, write a query in the editor, as shown.

len query in sql

Source Code:

–//LEN is used for calculating length of string
Select LEN(‘ The Universe ‘) AS [LEN (Length of Name)]
–//LEN is used for calculating length of string
 
–//DATALENGTH is used for calculating length of string
Select DATALENGTH(‘ The Universe ‘) AS [DATALENGTH (Length of Name)]
–//DATALENGTH is used for calculating length of string

(6) Then Execute or Press F5 to run the query and see the result as shown.

execute sql len query

Use of STORED PROCEDURES in SQL
Use of DATALENGTH Function in SQL
Use of CONCAT Function in SQL
Use of UNION and UNION ALL Operator in SQL
LEN (Transact-SQL)– Microsoft Docs

Leave a Reply