In this post explains how to use the DATALENGTH function in SQL Server (Transact-SQL) with syntax and examples.
In SQL Server (Transact-SQL), the DATALENGTH function returns the length of an expression, in bytes.
The syntax for the DATALENGTH function in SQL Server (Transact-SQL) is:
DATALENGTH( expression )
The data type that you wish to return the length for.
The DATALENGTH function can be used in the following versions of SQL Server (Transact-SQL):
Let's look at some SQL Server DATALENGTH function examples and explore how to use the DATALENGTH function in SQL Server (Transact-SQL).
For example:
SELECT DATALENGTH('AODBA.com');
Output: 16
SELECT DATALENGTH(' AODBA.com ');
Output: 22
SELECT DATALENGTH(1234);
Output: 4
SELECT DATALENGTH('2004-05-01');
Output: 10
SELECT DATALENGTH(' ');
Output: 1
SELECT DATALENGTH('');
Output: 0
SELECT DATALENGTH(NULL);
Output: NULL