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. It can be of any datatype. expression 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 finds the actual length of the data stored in each row. datalength is useful on varchar univarhcar, 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 their defined length.
datalength of any NULL data returns NULL.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute datalength.
Functions char_length, col_length