Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Unanswered: SQL Get latest records when date & time are seperate columns?

    Hi Guys,

    I joined to get an answer to this as its been wrecking my head all day...I hope someone can help:

    I have 2 tables:

    TransactionsImport (which is the destination table)
    TransactionsImportDelta

    I need to do the following:

    1. Get the records with the latest date and time in the destination table TransactionsImport
      Get the records with the latest date and time in the destination table TransactionsImportDelta table
      Insert the records from the TransactionsImportDelta table into TransactionsImport that have a greater date & time than the current records in TransactionsImport table.

    Problem is date & time are in seperate columns:

    Table structure:

    Date Time ID
    20111213 05154107 142201008300100
    20111213 05154122 B1L13ZY0000A07YD
    20111213 04504735 142201090002600
    20111213 04504737 142201095008300
    20111213 04504737 142201090002600

    Anybody that can help with a script would be great?

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    You may start from here:
    Code:
    select Date, Time
    from TransactionsImport
    where 
    Date in 
    (
    select max(Date) from TransactionsImport
    )
    and Time in
    (
    select max(Time) from TransactionsImport
    where Date in 
    (
    select max(Date) from TransactionsImport
    ));
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I think you want to look at this

    Deltas
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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