How to retrieve the nearest & highest value from a list

  • Hi,

    Suppose I have a table with values 8000, 6000, 4000, 2000, 1000

    I want retrieve the nearest & highest value for 4999 from the above list:

    SELECT top 1 * FROM AmountConfig ORDER BY ABS(Amount - 4999)

    The above query will get me the value 4000. But I need the value to be 6000 & not 4000. Even if i supply 4001 i need to retrieve 6000.

    How can I do this?

    Regards,

    Nithin

  • Nithin

    Can it be as simple as this:

    SELECT TOP 1 * FROM MyTable

    WHERE MyColumn > 4000

    ORDER BY MyColumn ASC

    John

  • select top 1 * from AmountConfig

    where Amount>4999

    order by Amount asc

    Try the above statement

  • Thanks a loooooot!!!!!!! John & Sridhar. I was soooo stupid to not to implement your simple idea!!:-)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply