Saturday, July 23, 2011

SQL LEN() Function


The LEN() Function

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

SQL LEN() Syntax

SELECT LEN(column_name) FROM table_name


SQL LEN() Example

We have the following "Persons" table:
P_IdLastNameFirstNameAddressCity
1HansenOlaTimoteivn 10Sandnes
2SvendsonToveBorgvn 23Sandnes
3PettersenKariStorgt 20Stavanger
Now we want to select the length of the values in the "Address" column above.
We use the following SELECT statement:
SELECT LEN(Address) as LengthOfAddress FROM Persons
The result-set will look like this:
LengthOfAddress
12
9
9

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server