Search code examples
sql-serversql-server-2005datalength

In SQL Server 2005, what is the difference between len() and datalength()?


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


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