如何将多条update语句合并为一条

需求:
如何将多条update语句合并为一条update语句:
如,update table1 set col='2012' where id='2014001'
      update table1 set col='1009' where id='2014003'
如何合并为一条?
 
在网上找了好久,总结了一个相对简单的语句(有些语句是函数语句,有点晕),如下:
  update table1 set col=(case id 
  when '2014001' then '2012'
  when '2014003' then '1009' end)
  where  id in('2014001','2014003')
这个还可以扩展为多个字段的,这个你自己去依葫芦画瓢了~
 
posted @ 2014-09-24 12:19  快乐菠菜  阅读(3844)  评论(0编辑  收藏  举报