Need SQL to select MAX datetime joining 2 tables

  • Need SQL to accomplish an UPDATE to TABLE_A's col_3 datetime w/ TABLE_B's max(col_4)

     where TABLE_A col_1 & col_2 = TABLE_B col_1 & col_2 AND TABLE_B col_3 = 1

    TABLE_A            TABLE_B

     col_1 int          col_1 int

     col_2 int          col_2 int

     col_3 datetime     col_3 int  

                        col_4 datetime

    Data Values:

    TABLE_A:  col_1 col_2 col_4

                155   137 1999-01-01 00:00:00.000

    TABLE_B:  col_1 col_2 col_3 col_4

                155   137     1 2005-01-01 00:00:00.000

                155   137     1 2002-01-01 00:00:00.000

                155   137     1 1999-01-01 00:00:00.000

    The following SQL is NOT guarantee'ing that I get the MAX TABLE_B col_4 datetime:

    update TABLE_A set col_3 = col_4

     from TABLE_A A, TABLE_B B

      where A.col_1 = B.col_1

        and A.col_2 = B.col_2

        and B.col_3 = 1

    IP Logged

    BT
  • Please do not cross post. I already answered your question here :

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=5&messageid=191642

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply