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
 

 

Select records which are 1 month old using sql query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rohanatl

New User


Joined: 21 Oct 2005
Posts: 22

PostPosted: Mon Sep 22, 2008 9:40 am    Post subject: Select records which are 1 month old using sql query
Reply with quote

HI All,
i want to retrieve the records from the db2 table where the condition is one month old from the date available in the table.
There is a field called date1 which will contain the date in which the records are inserted to the table,
i dont want to change the query every time,Can any one give me a query which will perform the same.
select * from Table name where date = one month old
Back to top
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2238
Location: @my desk

PostPosted: Mon Sep 22, 2008 9:56 am    Post subject:
Reply with quote

Hello,

You can try something like this.
Code:
select * from Table name where date = current date - 30 days

Thanks,
Arun
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 356
Location: New York

PostPosted: Mon Sep 22, 2008 10:21 am    Post subject:
Reply with quote

Refer the following link.

http://www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html

KSK
Back to top
View user's profile Send private message
murugan_mf

Active User


Joined: 31 Jan 2008
Posts: 148
Location: Chennai, India

PostPosted: Mon Sep 22, 2008 3:06 pm    Post subject:
Reply with quote

can you try this,
Code:
SELECT * FROM TBL_NAME WHERE DAYS(CURRENT DATE) - DAYS(DATE1) <= 30;
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Sep 23, 2008 9:00 am    Post subject:
Reply with quote

There are months that have more or less than 30 days. The - 30 DAYS calculation is garbage from a pure calendar point of view.
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 Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts SORT to append Month and YEAR in MMYY... tisamf DFSORT/ICETOOL 1 Wed Mar 08, 2017 4:46 pm
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


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