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: 30
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: 1610
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: 1610
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: 331
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: 1610
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: 331
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 Is the 'prompt' data for the DSLIST p... Willy Jensen TSO/ISPF 2 Tue Dec 06, 2016 4:38 am
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm


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