Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
To Fetch record with recent timestamp

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

New User


Joined: 27 Mar 2006
Posts: 95
Location: India

PostPosted: Wed Jun 18, 2008 4:40 pm    Post subject: To Fetch record with recent timestamp
Reply with quote

I need to fetch record with recent updated timestamp.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 4:46 pm    Post subject:
Reply with quote

IS it you want to fetch the records with the latest timestamp ???
use a max on your timestamp col ... if not pls provide example of wht you want to achieve ..
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 95
Location: India

PostPosted: Wed Jun 18, 2008 5:07 pm    Post subject:
Reply with quote

Thanks ashimer for your reply,my question is ,i need to pick the record with recently updated timestamp not with current timestamp table

Ex:
In table ,records will be updated every day,but i need to pick record which is updated last,it may be updated yesterday.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 5:13 pm    Post subject:
Reply with quote

Use this query

Code:


select * from table where timestamp_col = (select max(timestamp_col)
from table );

Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Jun 18, 2008 5:17 pm    Post subject:
Reply with quote

Rajesh,

do you need to know the last update for every 'ACCOUNT', or only the last updates, regardless of 'ACCOUNT'?
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 757
Location: Germany

PostPosted: Wed Jun 18, 2008 5:18 pm    Post subject:
Reply with quote

Hi !

I think ashimer's proposal is just .
Otherwise use something like the following. First fetch is your result.

Declare Cursor
Where Update_TS <= Current_Timestamp
OrderBy TUpdate_TS
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Jun 18, 2008 5:53 pm    Post subject:
Reply with quote

That's slick UmeySan. That cursor will pick up every row in the table.

And Ashimer's post will not work as imbedded sql.

the OP has not adequately described his requirements.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 6:05 pm    Post subject:
Reply with quote

The query which i have mentioned above will give the last updated record (as per the OP's req) ... now if its the requirement is for the last updated record for an "ACCOUNT" then this should work

Code:


select * from (select account,max(timestamp_col) from
table group by account) as temp;



PS: When the given requirement is not clear the OP will have to play with the hint given ...
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 757
Location: Germany

PostPosted: Wed Jun 18, 2008 7:11 pm    Post subject:
Reply with quote

@Dick:

Right, slicky but working. From the first question, not really the details have been clear. So i have to agree to ashimer once more.

And seriously i agree with you.

Finally we're all brothers in arms, struggling against the daily pitfalls of our job.
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 Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Repeat part of record multiple times Learncoholic DFSORT/ICETOOL 4 Tue Aug 29, 2017 11:33 am
No new posts Read two inputs and write into output... murali.andaluri DFSORT/ICETOOL 6 Wed Jul 26, 2017 7:35 pm
No new posts Need to write record of PS File in ex... Chandan1993 JCL & VSAM 1 Wed Jun 07, 2017 1:35 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us