Sql-server – In SQL Server 2005, what is the difference between len() and datalength()

datalengthsql-serversql-server-2005

What is the difference between len() and datalength() in SQL Server 2005?

Best Solution

DATALEN will return the number of bytes that are used to store the value:

http://msdn.microsoft.com/en-us/library/ms173486(SQL.90).aspx

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:

http://msdn.microsoft.com/en-us/library/ms190329.aspx