Length: LEN() to determine character length and maximum length
Date Revised: August 14 2009
This code shows how to use t-sql LEN() to find the length of characters in a given field for each row and find the maximum
characters for all rows.
-- Return length and field data of all rows
-- LEN: Returns the number of characters, instead of the number of bytes,
-- of the specified string expression, excluding trailing blanks
SELECT LEN(fieldName) AS [Length], fieldName
FROM
TableName
ORDER BY [Length] DESC;
-- Return max characters found in this field
SELECT MAX(LEN(fieldName))
FROM
TableName;
Sample results: