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: 2284
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 Reg:Displaying the particular month o... bhavana yalavarthi All Other Mainframe Topics 4 Sat Jul 08, 2017 8:13 pm
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
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
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us