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: 1738
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: 1738
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: 378
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: 1738
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: 378
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 Paasing symbolic parameter to instrea... Anirudh Anand JCL & VSAM 1 Thu Jul 27, 2017 1:22 pm
No new posts Passing data from REXX to C programme... chong.zhou CLIST & REXX 3 Wed Jul 26, 2017 9:11 pm
No new posts copying data without knowing location arunsoods DFSORT/ICETOOL 11 Thu Jul 20, 2017 1:03 pm
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm


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