Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Tue, 22 Feb 2005 @ 13:17:19 GMT

  <Prev Next>  
Next> Last>>  

Subj:   Finding previous record puzzle
From:   Anomy Anom

<-- Anonymously Posted: Tuesday, February 22, 2005 08:09 -->

Hi all,

Say I have a table with a date and time field in addition to my other fields including trans_id. Those date's and times do not correlate to when a record was inserted, but rather when the event on that line took place. This table is inserted from a feed coming from an AS/400 and records could be in any order.

How could I select the record previous to a given trans_id, or the previous 5 records; based on the date and time fields?

For example

     trans_id, trans_date, trans_time
     1234, 2005-02-20, 23:15:59
     1245, 2005-02-21, 01:23:44
     2014, 2005-02-21, 09:19:10
     1122, 2005-02-20, 19:35:26

Based on this table, I need to find which record comes before trans_id=1245 based on date/time. Should I sort, apply a sequence number to it and plug it into a volatile table for further querying, or do you have any other suggestions?

Much thanks.

  <Prev Next>  
Next> Last>>  
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023