Skip Navigation Links
Home
Articles
SQL Server 2012
SQL Server 2014
SQL Server 2016
FAQ
Forums
Practice Test
Bookstore
Tip of the Day : How to Call NEWID Function in a User-Defined Function
SQL Server Helper
Home > > Tip of the Day
SQL Server Helper - Tip of the Day

The LEN system function returns the number of characters of the specified string expression.  On the other hand, the DATALENGTH function returns the number of bytes used to represent any expression.  Here’s a summary of the similarities and differences between the LEN() and DATALENGTH() system functions:

Similarities

  • The LEN and DATALENGTH of NULL is NULL.
  • The return data type is BIGINT if the input expressions is of the VARCHAR(MAX), NVARCHAR(MAX) or VARBINARY(MAX) data types; otherwise the return data type is INT.

Differences

LEN DATALENGTH
Returns the number of characters of the specified string expression. Returns the number of bytes used to represent any expression.
Excludes trailing blanks in determining the number of characters. Includes trailing blanks in determining the number of bytes used.
Input parameter is of character or binary data type. Input parameter is of any data type.
LEN is a string function. DATALENGTH is a data type function.

Back to Tip of the Day List Next Tip