Len() and Datalength()

In this post we will go through two scalar functions

Len() is one of the string functions

Datalength is one of the Data type functions

so what does Len() do , it returns(int) the number of characters of the specified string expression, excluding trailing blanks.

excluding trailing blanks is an important note to remember when using Len() function

 

 

 

— It can also be used in select, where clause

Declare

@string varchar(100)

set @string =‘sqljunkieshare’

select LEN(@string)

 select * from dept

where LEN(dept_id)> 5

 

Datalength() is data type function (size of the data)

It returns the number of bytes used to represent any expression.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now you have a clear idea of what does LEN() and DATALENTH()  scalar functions do

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s