Search code examples
sqlsql-server-2000sql-update

Update multiple columns in multiple rows in one sql statement?


This pseudocode (inaccurate SQL) shows what I want to do.

update tableA (colA, colB, colC, colD)
select b.colA, b.colB, c.colC, c.colD
from tableB b 
    left outer join tableC c 
       on b.id = c.id
    inner join tableA a 
       on c.myNum = a.myNum 
    inner join tableD 
        on a.newId = f.newId
where f.imported = 1

How can I do this in a syntactically correct fashion?


Solution

  • Something like this:

    UPDATE TABLE 
    SET ...
    FROM Table1, Table2 ....
    WHERE .....
    
    
    update tableA 
     Set a.ColA = b.ColA,
         a.Colb = b.ColB,
         a.ColC = c.Colc,
         a.ColD = c.ColD
    from tableB b 
     left outer join tableC c 
       on b.id = c.id
     inner join tableA a 
       on c.myNum = a.myNum 
     inner join tableD 
        on a.newId = f.newId
     where f.imported = 1