Please help me to write code...

  • hi all,

    I have one table called "rates" with the following format.

    start date end date value

    5/26/2001 6/29/2001 5.5

    6/30/2001 7/27/2001 2

    7/28/2001 8/24/2001 1

    I need to write a query such that if i am entering any date value it should return the value corresponds to the date range.

    FOr ex: If i gave the input as 7/01/2001 it should return the value as "2".

    If i gave the input as [font="Arial"]04/01/2001[/font] then there are no corresponding value in the table. But for this the next higher date range value 5.5( 5/26/2001 6/29/2001 5.5) should return.

    Please write me a query for this and let me know if u need more details.

    Thanks in advance.

  • Couple of things first.

    One, read the first article I reference in my signature block about asking for assistance. Please following the instructions in that article on what and how you should post such requests for assistance as this. This will provide you with an additional benefit, tested code.

    Two, show us what you have tried trying to solve your problem. We may be able to help you with your logic instead of just writing the code you need.

  • Select top 1 * from rates where end_date >= Inputdate order by end_date



    Clear Sky SQL
    My Blog[/url]

  • Dave Ballantyne (9/10/2009)


    Select top 1 * from rates where end_date >= Inputdate order by end_date

    Based on the sample data, I'd drop the = from the >= in the where clause.

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

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