Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us