在一个sql语句中更新多行中的多个列?

时间:2010-08-27 14:29:53

标签: sql sql-server-2000 sql-update

这个伪代码(不准确的SQL)显示了我想要做的事情。

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

我怎样才能以语法正确的方式做到这一点?

2 个答案:

答案 0 :(得分:2)

这样的事情:

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

答案 1 :(得分:0)

SQL> select *from Dewashish84;

E_ID E_NAME        E_EDUCATION
---------- ------------- ---------------

   100 dewa          MCA
   101 Raj           MSCIT
   145 mohan         BA
   103 ram           MTECH
     5 Sohan         BTECH

SQL>

update harshad set E_NAME= decode(E_EDUCATION,'MCA','dewa','MSCIT','Raj','BA','mohan',
     'MTECH','ram');

 5 rows updated.