LEN checks the length in characters, for example. "a" = 1 char
select max(len(fieldA)) from tbl
DATALENGTH checks for size in bytes, NVarchar takes 2 bytes per character
select max(datalength(fieldA)) from tbl
To get all the rows in the table that have the maximum data length in FieldA,
select * from tbl join (select MAX(LEN(fieldA)) maxlen from tbl) l on l.maxlen = LEN(tbl.fieldA)
RichardTheKiwi
source share