SQL Inner join 2 tables with multiple column conditions and update

marilyn picture marilyn · Jul 1, 2010 · Viewed 109.8k times · Source

I am using this script, trying to join 2 tables with 3 conditions and update T1:

Update T1 set T1.Inci = T2.Inci 
ON T1.Brands = T2.Brands 
AND T1.Category= T2.Category
AND T1.Date = T2.Date

but I encounter:

Incorrect syntax near the keyword 'ON'.

Can't figure it out why.

Answer

Robin Day picture Robin Day · Jul 1, 2010
UPDATE
    T1
SET
    T1.Inci = T2.Inci 
FROM
    T1
INNER JOIN
    T2
ON
    T1.Brands = T2.Brands
AND
    T1.Category= T2.Category
AND
    T1.Date = T2.Date