日期:2014-05-17  浏览次数:20565 次

关于sql语句修改表中所有满足条件的语句
现有表A 结构如下
id  数字1 数字2 数字3 数字4 数字5
1     1     2     3    3     5
2     4     2     5    0     4
3     3     2     1    1     6
4     2     5     0    3     3

我想改变表中所有字段的1为99 如何更改 

实现结果为
id  数字1 数字2 数字3 数字4 数字5
1     99     2     3    3     5
2     4     2     5    0     4
3     3     2     99    99     6
4     2     5     0    3     3

------解决方案--------------------

update [表A]
 set 数字1=case 数字1 when 1 then 99 else 数字1 end,
     数字2=case 数字2 when 1 then 99 else 数字2 end,
     数字3=case 数字3 when 1 then 99 else 数字3 end,
     数字4=case 数字4 when 1 then 99 else 数字4 end,
     数字5=case 数字5 when 1 then 99 else 数字5 end

------解决方案--------------------
case when