Search code examples
sql-server-2008t-sqlssms-2012

return best value found for query in N seconds


I have this query:

SELECT MAX(LEN(MyColumn)) FROM MyTable

But there are many rows and no index on the column. Is there a way to get the highest MAX(LEN(MyColumn)) found in N seconds instead of the absolute maximum?


Solution

  • If you really need such functionality you can create function with loop containing sequential comparing of MyColumn length with some max value and checking you query time limit. In case each record contains id column you can implement some kind of cache - store previously calculated max value and maximal checked id value somewhere in your database so next time you need to check only new records. Of course it depends on your real task.