Difference Between LEN and DATALENGTH Functions in SQL Server

Posted by Murugavelmsc under Sql Server on 2/27/2013 | Points: 10 | Views : 2582 | Status : [Member] | Replies : 3
Difference Between LEN and DATALENGTH Functions in SQL Server

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Pandians on: 2/28/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Check It Out!
DECLARE @Data VARCHAR(10)

SELECT @Data='Funda '
SELECT LEN(@Data) [LEN], DATALENGTH(@Data) [DATALENGTH]
GO

LEN :- Length of Data
DATALENGTH :- Number of Byte(s) used
LEN	DATALENGTH

5 6


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Pandian,

LEN - will right trim the blank values?

Thanks,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhuritumati on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
DATALEN will return the number of bytes that are used to store the value.

LEN will return the number of characters in a string. Since a string can use single or double-byte characters, this differs from DATALENGTH in that you will always get 1, no matter how long a single character is





Software Engineer

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response