Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > how to fetch the latest time record from a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-08, 08:15
kimourina kimourina is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
Question how to fetch the latest time record from a table

Hi,

Iam currently working on a sybase project ,where we record the run information with data and time.

I wanted to fetch the run which was run last on the day:

eg:I perform multiple runs on a day say 10:00,11:00,12:35 etc

if I wanted to pick the records with the time 12:35 how do i fetch irrepective of looking for time and giving it explicitly...!!

My procedure should opick up this value by default and then go ahead with futher logic.

Can someone quickly help me in this regard...


Thanks in advance,
Kim
Reply With Quote
  #2 (permalink)  
Old 06-12-08, 09:00
Martijnvs Martijnvs is offline
Who? Me?
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 273
That's only possible when there's a column with a datetime or timestamp-value. You can then filter on the latest batch of records processed.
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #3 (permalink)  
Old 06-12-08, 10:48
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
select blah, blah
from runs r
,(select runtime=max(runtime) from runs) m
where r.runtime=m.runtime
Reply With Quote
  #4 (permalink)  
Old 06-12-08, 11:01
kimourina kimourina is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
Thanks for your suggesstions..!!

I have to capture the date and time at that moment.I do not want to go for time stamp.

currently Im using convert(varchar(20),getDate()) to capture the rundate and time which will geive the date and time as mon dd yyyy 00:00 AM/PM format.

If I say select max(rundate) on this , will that workout?

Is there any better way to capture date and time (hh.mm) so that I can pick up the latest run when required??

Please advice.
Reply With Quote
  #5 (permalink)  
Old 06-12-08, 11:18
mike_bike_kite mike_bike_kite is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 944
You don't have to use a timestamp for this, you're fine using a date field for this. Just insert the current time with getdate() into the date field when you add the data. Then when wanting to grab the data for the latest record you could.
Code:
select data from table where date_added = ( select max(date_added ) from table )

Mike
Reply With Quote
  #6 (permalink)  
Old 06-12-08, 16:42
kimourina kimourina is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
Thank you..!!My problem solved..!!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On