IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need a query to find 30 days old data


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 51
Location: India

PostPosted: Fri Oct 23, 2015 11:04 am
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Fri Oct 23, 2015 12:17 pm
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.
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
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Fri Oct 23, 2015 8:55 pm
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: 446
Location: USA

PostPosted: Fri Oct 23, 2015 8:55 pm
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
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Fri Oct 23, 2015 9:35 pm
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: 446
Location: USA

PostPosted: Sat Oct 24, 2015 12:06 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts SCOPE PENDING option -check data DB2 2
No new posts RC query -Time column CA Products 3
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top