+ -
当前位置:首页 → 问答吧 → 分批次更新同一个表中相同字段的值。急!!!

分批次更新同一个表中相同字段的值。急!!!

时间:2011-12-03

来源:互联网

表名为:COMUST
表结构如下:
Pnumber name Bchno Pset Pact


  1 HB500 7901 2404 2369
  1 HC300 7901 560 578
  1 water 7901 344 349
  1 HB500 7902 2422 2479
  1 HC300 7902 542 547
  1 water 7902 339 372



Pnumber 为主键,我想同时更新Bchno 为 7901,name为HB500, Bchno 为 7902,name为HB500的Pact值,并且Bchno 为 7901,name为HB500这条记录的Pact值更新为2404,Bchno 为 7902,name为HB500这条记录的Pact值更新为2422,用SQ语句该怎么做呢?

请教各位高手,很急啊,万分感谢!!!

作者: Nong_Ming_Shuai   发布时间: 2011-12-03

SQL code

update tb
set 更新的列 = (case when 条件1 then 值1
                    when 条件2 then 值2
                    when 条件3 then 值3
               else 更新的列 end)

作者: AcHerat   发布时间: 2011-12-03

update tb
set clo= case when 。。。then 。。。。
when 。。。then。。。

when。。。。then。。
else。。。
end

作者: Beirut   发布时间: 2011-12-03

SQL code
update COMUST set Pact=(case when Bchno='7901' and name='HB500' then 2404
when Bchno='7902' and name='HB500' then 2422 end)
where Bchno='7901' and name='HB500' or Bchno='7902' and name='HB500'

作者: qianjin036a   发布时间: 2011-12-03

要加 where 子句的,否则就是全表更新1

作者: qianjin036a   发布时间: 2011-12-03

你不如写两个update

作者: ssp2009   发布时间: 2011-12-03

热门下载

更多