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
 
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: 2287
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: 355
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 Inefficient BUILD - VB records paddin... Daniel Prosser SYNCSORT 4 Thu Dec 14, 2017 3:52 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 2 Wed Dec 06, 2017 1:50 am
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm

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