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: