How to get the value of max length in sql server

paa picture paa · Sep 1, 2014 · Viewed 16.8k times · Source

i would like to ask you if there is a way to get the value of maxlength of column in ms sql server.
For example in the table A we have:

id  | value
----+--------
 1  | 0123
 2  | 00034567
 3  | 547

The desired result for this data set is 00034567.

Wherever i have searched for this problem i get the answer select max(len(value)) which is not what i need, because it gives the max number of characters of the value and not the value itself.

Any ideas?

Answer

Vland picture Vland · Sep 1, 2014
SELECT TOP 1 t.value
FROM table AS t
ORDER BY LEN(t.value) DESC