Monday, 26 August 2013

Difference Between LEN and DATALENGTH Functions in SQL Server





LEN:- It shows actual Length of Declared Variable not as it’s Capacity.
Explanation:-

Char(50),Here we declare on Char variable with 50 character capacity .
But we assigned ‘Rahul’ only 5 character.
This Actual Length is called Len of a Variable.

DATALENGTH:- But DATALENGTH  shows the capacity of a Variable.
Char(50) here 50 is the capacity of char Variable.


DECLARE @str 
CHAR(50)

SET @str='Rahul'

SELECT LEN(@str) AS LenCount

SELECT DATALENGTH(@str) AS DataLengthCount











4 comments:

Anonymous said...

please describe it sir ...............

Kush Tiwari said...

please describe it sir

Ramu kumar Gupta said...

Thanks for Comment.

Now i declared with Details.

Thanks for Comment once again.

Ramu kumar Gupta said...

Thanks for Comment.

Now i declared with Details.

Thanks for Comment once again.