• You have to give a table variable an alias in order to do this kind of thing.

    DECLARE @MyTable TABLE

    (

    COl1 INT,

    COl2 INT

    );

    SELECT MT.Col1 FROM @MyTable AS MT;

    UPDATE MT

    SET Co2 = A.Cik2

    FROM @MyTable AS MT

    INNER JOIN Table2 AS A

    WHERE A.Col1 = MT.Col1;

    Even better yet, on the Update From, use Merge instead.

    MERGE INTO @MyTable AS Tgt

    USING (SELECT Cik2, Col1 FROM dbo.Table2) AS Src

    ON Tgt.Col1 = Src.Col1

    WHEN MATCHED THEN UPDATE

    SET Col1 = Src.Col1;

    Merge has a few advantages over Update From, in terms of ACID-compliance in the update. It's also ISO compliant, if that matters to you, where Update From is T-SQL proprietary. But the ACID properties, like Update From can have multiple, conflicting updates to the same row, while Merge can't, are what really matter.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon