DATALENGTH
Returns the number of bytes occupied by any expression.
grammar
DATALENGTH ( expression )
parameter
expression
any type of expression.
return type
int
Notes
DATALENGTH is particularly useful for varchar , varbinary , text , image , nvarchar , and ntext data types, because these data types can store variable-length data.
The result of a DATALENGTH of NULL is NULL.
Explains that the compatibility level may affect the return value. For more information on compatibility levels, see sp_dbcmptlevel.
Example
This example finds the length of the pub_namepubs
column in the table .
USE pubs
GO
SELECT length = DATALENGTH(pub_name), pub_name
FROM publishers
ORDER BY pub_name
GO
Here is the result set:
length pub_name
----------- ----------------------------------------
20 Algodata Infosystems
16 Binnet & Hardley
21 Five Lakes Publishing
5 GGG&G
18 Lucerne Publishing
14 New Moon Books
17 Ramona Publishers
14 Scootney Books