If you are concerned about the actual length of the field and not the data stored inside it, you can use col_length functon
e.g. select col_length("<table_name>",
If you want to find the length of data stored in the field, you can use "datalength" finction described above. For char/varchar columns you can also use "char_length" function
e.g. select char_length(<column_name>)
Main Topics
Browse All Topics





by: bowemcPosted on 2007-07-02 at 09:32:18ID: 19404884
datalength
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, varbinary, text, 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