tags:

views:

56

answers:

2

i've been using the following query:

select LEN(columnname) as columnmame 
  from dbo.amu_datastaging

This works, but is there a way to only return the greatest value instead of all the values?

So if i return 1million records and the longest length is 400, the query would just return the value of 400?

+6  A: 
 select max(LEN(columnname)) as columnmame from dbo.amu_datastaging
HLGEM
+1  A: 

This should do the trick:

SELECT MAX(LEN(columnname)) FROM dbo.amu_datastaging

Not that this won't be fast with a million records, the DB is going to need to compute the length of each value in the table on every query. Consider caching this in an extra "length" field if you really have millions of records.

Alexander Malfait