Tip of the Day : How to Join with an Inline User-Defined Function

SQL Server Helper - Tip of the Day

Similarities and Differences Between LEN and DATALENGTH Functions

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