DATALENGTH function [System]

Returns the length, in bytes, of the underlying storage for the result of an expression.

Syntax
DATALENGTH( expression )
Parameters
  • expression   Usually a column name. If expression is a string constant, you must enclose it in quotes.

Returns

UNSIGNED INT

Remarks

The return values of the DATALENGTH function are as follows:

Data type DATALENGTH
SMALLINT 2
INTEGER 4
DOUBLE 8
CHAR Length of the data
BINARY Length of the data

This function supports NCHAR inputs and outputs.

Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statement returns the length of the longest string in the CompanyName column.

SELECT MAX( DATALENGTH( CompanyName ) )
FROM Customers;

The following statement returns the length of the string '8sdofinsv8s7a7s7gehe4h':

SELECT DATALENGTH( '8sdofinsv8s7a7s7gehe4h' );