Difference between LEN and DATALENGTH

LEN and DATALENGTH are returns the count of given value. LEN is count the length of characters,But DATALENGTH count the bytes of the character.


DECLARE @v NVARCHAR(50)

SELECT @v ='Vinoth'

SELECT LEN(@v) AS[LEN],DATALENGTH(@v) AS [DATALENGTH]

LEN         DATALENGTH
----------- -----------
6           12
(1 row(s) affected)

 ----------------------------------------------------------------------------
LEN doesn't count trailing spaces.

SELECT DATALENGTH('Vinoth ') AS [DATALENGTH], LEN('Vinoth ') AS [LEN]

DATALENGTH  LEN
-----------      -----------
7                  6
(1 row(s) affected)