Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
I need a query for this situation

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
naveensri2005
Currently Banned

Active User


Joined: 22 Mar 2005
Posts: 51
Location: chennai

PostPosted: Wed May 18, 2005 5:25 pm    Post subject: I need a query for this situation
Reply with quote

hi

I have one table is there . that table contain 2000 reacords are there. in that table contain date fields is there? but i want to retrive only last five days records only how to write the query?



naveens
Back to top
View user's profile Send private message
References
MGIndaco

Moderator


Joined: 10 Mar 2005
Posts: 478
Location: Milan, Italy

PostPosted: Wed May 18, 2005 7:50 pm    Post subject:
Reply with quote

I've some problem in understanding your post but i think that you can subtract from current date all the day you need as you can see below:
Code:
SELECT * FROM MYDB.MYTB     
WHERE DATE = CURRENT_DATE - 5 DAYS
Back to top
View user's profile Send private message
priyesh.agrawal

Global Moderator


Joined: 28 Mar 2005
Posts: 1509
Location: Chicago, IL

PostPosted: Wed May 18, 2005 8:17 pm    Post subject: Re: i need query for this situalation?
Reply with quote

Is this code going to extract records only for last fifth day from today.

Quote:
I've some problem in understanding your post


I think naveensri2005 asked all the recs for the all last five days.

so it could have been.

Code:
SELECT * FROM MYDB.MYTB
            WHERE DATE IN (
                                      CURRENT_DATE,
                                      CURRENT_DATE - 1 DAYS.
                                      CURRENT_DATE - 2 DAYS.
                                      CURRENT_DATE - 3 DAYS.
                                      CURRENT_DATE - 4 DAYS.
                                    );


Regards,

Priyesh.
Back to top
View user's profile Send private message
MGIndaco

Moderator


Joined: 10 Mar 2005
Posts: 478
Location: Milan, Italy

PostPosted: Wed May 18, 2005 8:28 pm    Post subject:
Reply with quote

Or you can also specify:

Code:
SELECT * FROM MYDB.MYTB     
WHERE DATE >= CURRENT_DATE - 5 DAYS

It's another way to do the same request...
Back to top
View user's profile Send private message
ajay_dheepak

New User


Joined: 12 May 2005
Posts: 33
Location: Chennai

PostPosted: Thu May 19, 2005 2:49 pm    Post subject:
Reply with quote

SELECT * FROM MYDB.MYTB
WHERE DATE >= CURRENT DATE - 4 DAYS
AND DATE <= CURRENT DATE;
Back to top
View user's profile Send private message
MGIndaco

Moderator


Joined: 10 Mar 2005
Posts: 478
Location: Milan, Italy

PostPosted: Thu May 19, 2005 8:52 pm    Post subject:
Reply with quote

OPS... icon_redface.gif
Back to top
View user's profile Send private message
MGIndaco

Moderator


Joined: 10 Mar 2005
Posts: 478
Location: Milan, Italy

PostPosted: Thu May 19, 2005 8:57 pm    Post subject:
Reply with quote

Code:
SELECT * FROM MYDB.MYTB
WHERE DATE BETWEEN CURRENT_DATE - 4 DAYS AND CURRENT_DATE

This is better... icon_wink.gif
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1