Open In App

DATALENGTH() Function in SQL Server

DATALENGTH() :
This function returns the length of an expression and expression length will be in bytes.

Syntax :



DATALENGTH( expression )  

Returns :
It returns the number of bytes used to represent an expression.

Example-1 :
Return the length of an expression.



SELECT DATALENGTH('Geeksforgeeks');

Output :

13

Example-2 :
Check DATALENGTH() Function count trailing spaces or not.

SELECT DATALENGTH('GFG   ');

Output :

6

Example-3 :
Check DATALENGTH() Function count leading spaces or not.

SELECT DATALENGTH('    GFG');

Output :

7

Example-4 :
DATALENGTH() Function return NULL, if the expression is NULL.

SELECT DATALENGTH(NULL);

Output :

NULL
Article Tags :
SQL