Skip to Content
avatar image
Former Member

Need a Query to check a range of dates in the given range.

Hi Guys,

<u>My Query is :</u>

select * from DSR where d1 between Log1 and Log2

d1 is given by us as input.

I am checking d1 in between Log1 and Log2.

Is there any possibility that if I give date range like d1 to d2, it has to check all the dates between d1 and d2 one by one in the Log1 & Log2 range and it has to return all the records which are matching with the dates between d1 & d2.

Do I need to put any loop here for each and every date.

Please help me out in this. thanks

Venkat.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Aug 19, 2007 at 10:22 AM

    Hi

    if you declare S_DATE field as Select-options

    generally we check this against a single field as

    SELECT...FROM...VBAK...

    WHERE AUDAT IN S_DATE.

    here it seems it has to be checked by both log1 and log2 dates

    then you can use

    select * from DSR where

    LOG1 >= S_DATE-low and LOG2 <= S_DATE-high.

    provided both LOW and HIGH of date fields are netered on selection screen.

    <b>Reward points for useful Answers</b>

    Regards

    Anji

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Anji Reddy,

      I am very thankful to you for your reply.

      I am writing the same query in SQL Server, I dont have select-options over there like in ABAP. what to do now for my query.

      Please try to solve my problem bcoz i am struck up with this from last four days.

      I am not able to continue my project. Please helpl out.

      Thank you sir,

      Venkat.

  • avatar image
    Former Member
    Aug 19, 2007 at 02:06 PM

    If Log1 and Log2 are your database field names and d1 and d2 are the input date values from the user, you need to do something like:

    SELECT * FROM dsr 
         WHERE log1 BETWEEN d1 AND d2 
               AND log2 BETWEEN d1 AND d2 .

    The first item in the where block is the field name, this is followed by the condition to apply for the selection.

    Andrew

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 09:25 AM

    i think u have to handle five cases separately......

    1) d1 < log1 and d2< log1 - then no value will be fetched.

    2) d1 <log1 and (d2 between log1 and log2)

    3)d1> log2 and d2> log2 - then no value will be fetched.

    4) (d1 between log1 and log2) and d2 > log2

    5) d1 >log1 and d2 <log2

    6) d1< log1 and d2> log2

    reward if helpful.

    Add comment
    10|10000 characters needed characters exceeded