DATALENGTH() Function in SQL Server
DATALENGTH() :
This function returns the length of an expression and expression length will be in bytes.
Syntax :
DATALENGTH( expression )
- Parameter –
This method accepts a single-parameter as mentioned above and described below as follows. - Expression –
It is an expression of the data type to return the length for. If expression is NULL, it returns NULL.
Returns :
It returns the number of bytes used to represent an expression.
Example-1 :
Return the length of an expression.
SELECT DATALENGTH('w3wiki');
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
Contact Us