Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Posts
    6

    Question Unanswered: 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

  2. #2
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    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!

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    select blah, blah
    from runs r
    ,(select runtime=max(runtime) from runs) m
    where r.runtime=m.runtime

  4. #4
    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.

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  6. #6
    Join Date
    Jun 2008
    Posts
    6
    Thank you..!!My problem solved..!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •