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
 

 

Need a query to find 30 days old data

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

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Fri Oct 23, 2015 5:24 am    Post subject: Need a query to find 30 days old data
Reply with quote

Need a query to find 30 days old data from a table. Need to compare with time stamp column. whenever the sql is executed it need to fetch the 30 days old data by using time stamp column.
Back to top
View user's profile Send private message

vickey_dw

New User


Joined: 10 Jun 2015
Posts: 42
Location: India

PostPosted: Fri Oct 23, 2015 11:04 am    Post subject:
Reply with quote

Try below

Code:
Select * from table-name where
(column_name > (Current_TimeStamp - 30 Days))



Looks like first time i have contributed icon_smile.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1651
Location: NY,USA

PostPosted: Fri Oct 23, 2015 12:17 pm    Post subject:
Reply with quote

There are too many topics on the same, please search . Are you sure it's not a 1 month old and 30 days?
E.g.
http://ibmmainframes.com/viewtopic.php?p=329919#329919
Back to top
View user's profile Send private message
mf_karthik

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Fri Oct 23, 2015 8:38 pm    Post subject: Reply to: Need a query to find 30 days old data
Reply with quote

I need to fetch the last 30 days record. Whenever my query is running it need to fetch the last 30 days record.

I tried the below one its not working

SELECT * FROM Test.Test1_ABC
WHERE DATE(timestamp) = CURRENT DATE - 30 DAY ..

trying for other options..pls let me know if anything needs to be changed
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1651
Location: NY,USA

PostPosted: Fri Oct 23, 2015 8:55 pm    Post subject:
Reply with quote

Quote:
I tried the below one its not working


Please post the error without that no one can help here better.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 343
Location: USA

PostPosted: Fri Oct 23, 2015 8:55 pm    Post subject: Reply to: Need a query to find 30 days old data
Reply with quote

Quote:
I tried the below one its not working

SELECT * FROM Test.Test1_ABC
WHERE DATE(timestamp) = CURRENT DATE - 30 DAY ..

trying for other options..pls let me know if anything needs to be changed

This should work perfectly well provided you put the right column name. Are you using the correct column name?:
Quote:
WHERE DATE(Column Name containing timestamp in table Test1_ABC) = CURRENT DATE - 30 DAY

This is the only piece which could go wrong here.

.
Back to top
View user's profile Send private message
mf_karthik

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Fri Oct 23, 2015 9:19 pm    Post subject:
Reply with quote

Rohit Umarjikar wrote:
Quote:
I tried the below one its not working


Please post the error without that no one can help here better.


NO rows retrieved
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1651
Location: NY,USA

PostPosted: Fri Oct 23, 2015 9:35 pm    Post subject:
Reply with quote

Quote:
NO rows retrieved

Then there must not be any rows. and your one line answer would not solve the issue, please provide specific data as it works at my end.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 343
Location: USA

PostPosted: Sat Oct 24, 2015 12:06 am    Post subject: Reply to: Need a query to find 30 days old data
Reply with quote

Oh.. And one more thing. You will need '>=' in place of '=' If you want the data for last 30 days and Not the 30th day only.

.
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 Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm
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 SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts Overriding PS data in rexx Shaheen Shaik CLIST & REXX 8 Fri Mar 03, 2017 5:08 pm


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