In contrast to col_length, which finds the defined length of a column, datalength reports the actual length, in bytes, of the data stored in each row. Use this function on varchar, nvarchar, univarchar, varbinary, text, unitext, and image datatypes, since they can store variable lengths and do not store trailing blanks. datalength of any NULL data returns NULL. When a char value is declared to allow NULLS, Adaptive Server stores it internally as a varchar. All other datatypes report their defined length. Here is an example that finds the length of the pub_name column in the publishers table:
select Length = datalength(pub_name), pub_name from publishers
Length pub_name ------ ------------------------ 13 New Age Books 16 Binnet & Hardley 20 Algodata Infosystems (3 rows affected)