• Paul, please keep questions on one issue in one thread in the future. The issue is still the aliasing. When you get that error in Query Analyzer or SMSS, double click it. It will bring you right to Line 102 where you have:

    UPDATE @EntityDateTimes

    SET EventID=(SELECT TOP 1 EventID

    FROM tkEntityHistory )

    WHERE EntityID=@EntityDateTimes.EntityID

    AND [DateTime]=@EntityDateTimes.[DateTime])

    You cannot use Fully qualified names with Table variables.

    This needs to be:

    UPDATE @EntityDateTimes

    SET EventID=(SELECT TOP 1 EventID

    FROM tkEntityHistory

    WHERE EntityID=E.EntityID

    AND [DateTime]=E.[DateTime])

    FROM @EntityDateTimes E

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]