Returns the actual length, in bytes, of the specified column or string.
datalength(expression)
is a column name, variable, constant expression, or a combination of any of these that evaluates to a single value. expression can be of any datatype, an is usually a column name. If expression is a character constant, it must be enclosed in quotes.
Finds the length of the pub_name column in the publishers table:
select Length = datalength(pub_name) from publishers
Length ----------- 13 16 20
datalength, a system function, returns the length of expression in bytes.
datalength returns the uncompressed length of a large object column, even when the column is compressed.
For columns defined for the Unicode datatype, datalength returns the actual number of bytes of the data stored in each row. For example, this is what is returned if a unitext column ut contains row value U+0041U+0042U+d800dc00:
select datalength(ut) from unitable ------------- 8
datalength finds the actual length of the data stored in each row. datalength is useful on varchar, univarchar, varbinary, text, and image datatypes, since these datatypes can store variable lengths (and do not store trailing blanks). When a char or unichar value is declared to allow nulls, Adaptive Server stores it internally as varchar or univarchar. For all other datatypes, datalength reports the defined length.
datalength accepts the text_locator, unitext_locator, and image_locator LOB datatypes.
datalength of any NULL data returns NULL.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute datalength.
Functions char_length, col_length