开发者

SQL column length query

i've been using the following开发者_Go百科 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?


 select max(LEN(columnname)) as columnmame from dbo.amu_datastaging


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜