Returns the number of bytes used to represent any expression.
DATALENGTH(expression)
int
DATALENGTH is especially useful with varchar, varbinary, text, image, nvarchar, and ntext data types because these data types can store variable-length data.
The DATALENGTH of NULL is NULL.
Note Compatibility levels can affect return values. For more information about compatibility levels, see sp_dbcmptlevel.
This example finds the length of the pub_name column in the publishers 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
(8 row(s) affected)
CAST and CONVERT | System Functions |
Data Types |