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
 

 

Query to fetch previous day 24 hrs data

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

New User


Joined: 27 Apr 2009
Posts: 22
Location: mumbai

PostPosted: Sun May 24, 2015 3:00 pm    Post subject: Query to fetch previous day 24 hrs data
Reply with quote

Hi All,

My requirement is to fetch records from table x whose last update time stamp is between yesterday 00.00.00.000000 and yesterday 23.59.59.999999.

for example if suppose i am running the query in batch spufi today say current date is 2015-05-24. then i have to get records from the table which are got updated between '2015-05-24.00.00.00.000000' and '2015-05-24.23.59.59.999999'.

is the above query is possible. I am planing to execute the query in batch and schedule it thru a job which will run daily and generate report.

I have the last update column in the table.
Back to top
View user's profile Send private message

mjadwani2785

New User


Joined: 28 Apr 2009
Posts: 89
Location: Noida , Dublin

PostPosted: Mon May 25, 2015 4:50 am    Post subject:
Reply with quote

Hi ,

Try this in where clause of your SQL

where DATE( timestamp_col - 1 DAY) = CURRENT DATE - 1 DAY

Hope this helps !!

Regards,
MJ
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


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

PostPosted: Thu May 28, 2015 8:00 pm    Post subject:
Reply with quote

Quote:
My requirement is to fetch records from table x whose last update time stamp is between yesterday 00.00.00.000000 and yesterday 23.59.59.999999.


Quote:
for example if suppose i am running the query in batch spufi today say current date is 2015-05-24. then i have to get records from the table which are got updated between '2015-05-24.00.00.00.000000' and '2015-05-24.23.59.59.999999'.


they are contradictory.

Declare something like this and use it in where condition.

Code:
01 date-range
   05 date-to
        10 current-date PIC X(10).
        10 high-timestmp PIC X(16) VALUE '.23.59.59.999999'.
   05 date-from
        10 current-date PIC X(10).
        10 low-timestmp PIC X(16) VALUE '.00.00.00.000000'.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Thu May 28, 2015 9:42 pm    Post subject: Reply to: Query to fetch previous day 24 hrs data
Reply with quote

Quote:
My requirement is to fetch records from table x whose last update time stamp is between yesterday 00.00.00.000000 and yesterday 23.59.59.999999.


it looks like you are overshooting ...
wouldn' t it be simpler just to ask for the rows with a last update date of yesterday ???
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Sun May 31, 2015 7:53 pm    Post subject:
Reply with quote

mjadwani2785 wrote:
Hi ,

Try this in where clause of your SQL

where DATE( timestamp_col - 1 DAY) = CURRENT DATE - 1 DAY

Hope this helps !!

Regards,
MJ
"- 1 DAY" is a nice option, but once is enough:
Code:
WHERE DATE(timestamp_update) = CURRENT DATE - 1 DAY
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
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
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts How to get previous month in SYMNAMES Suganya87 SYNCSORT 9 Fri Oct 28, 2016 1:37 pm


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