• Garadin (11/18/2008)


    Glad we could help. One other word of caution. You are selecting the Top 1 in that update clause, but you aren't ordering by anything. This could lead to unexpected/inconsistent results if you routinely have more than one EventID for each EntityID and DateTime. If you are sure that you DON'T ever have more than 1 EventID for any given EntityID or Datetime, then your query can be simplified to eliminate the subquery as so:

    UPDATE @EntityDateTimes

    SET EventID= EH.EventID

    FROM @EntityDateTimes E

    INNER JOIN tkEntityHistory EH ON E.EntityID=EH.EntityID AND E.[DateTime]=EH.[DateTime]

    I'll leave it to someone else to gripe about the cursors :hehe:

    Man, I hate it when someone else not only beats me with an answer, but has a better one 😉

    Nice job Seth.

    I wasn't going to complain about the cursor either. I just concentrated on the OP's question.