Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Unanswered: DB2 Select Question

    ppl,

    I need some help regarding a DB2 select statement - I have three fields in a table like this

    YEAR CHAR(4) N 2011
    MONTH CHAR(2) N 01
    DAY CHAR(2) N 01

    I need to select data between 2 dates. I tried giving this but it said no rows found . How should i do this

    WHERE ("YEAR" > '2011'
    AND "MONTH" > '01'
    AND "DAY" > '01' )
    AND ("YEAR" < '2011'
    AND "MONTH" < '03'
    AND "DAY" < '01' )
    FOR FETCH ONLY WITH UR

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    How about these samples?

    Sample1:
    Code:
     WHERE (    YEAR  > '2011' 
            OR
                YEAR  = '2011'
            AND MONTH > '01'
            OR
                YEAR  = '2011'
            AND MONTH = '01'
            AND DAY   > '01'
           )
       AND (    YEAR  < '2011' 
            OR
                YEAR  = '2011'
            AND MONTH < '03' 
            OR
                YEAR  = '2011'
            AND MONTH = '03' 
            AND DAY   < '01'
           )
    or

    Sample2:
    Code:
     WHERE YEAR || MONTH || DAY
           BETWEEN '20110102'
               AND '20110228'
    Last edited by tonkuma; 03-25-11 at 07:47.

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Smile Thank you Buddy - it worked

    Thanks a Lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •