Returns the length, in bytes, of the underlying storage for the result of an expression.
DATALENGTH( expression )
expression expression is usually a column name. If expression is a string constant, you must enclose it in quotes.
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 |
SQL/2003 Vendor extension.
The following statement returns the value 27, the longest string in the CompanyName column.
SELECT MAX( DATALENGTH( CompanyName ) ) FROM Customers;
The following statement returns the value 22, the length of the string '8sdofinsv8s7a7s7gehe4h':
SELECT DATALENGTH( '8sdofinsv8s7a7s7gehe4h' );