If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Select Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-11, 06:03
sandyin1 sandyin1 is offline
Registered User
 
Join Date: Mar 2011
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 03-25-11, 06:21
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
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 06:47.
Reply With Quote
  #3 (permalink)  
Old 03-25-11, 07:29
sandyin1 sandyin1 is offline
Registered User
 
Join Date: Mar 2011
Posts: 2
Smile Thank you Buddy - it worked

Thanks a Lot
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On