Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ 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
View previous topic :: :: View next topic  
Author Message
naveensri2005
Currently Banned

New 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

MGIndaco

Active User


Joined: 10 Mar 2005
Posts: 432
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

Senior Member


Joined: 28 Mar 2005
Posts: 1452
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

Active User


Joined: 10 Mar 2005
Posts: 432
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: 32
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

Active User


Joined: 10 Mar 2005
Posts: 432
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

Active User


Joined: 10 Mar 2005
Posts: 432
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us