日期:2014-05-18  浏览次数:20397 次

update的问题,在线等,急!!
表中有一个status_div值,
我想做的是,
当该status_div的值是1的时候,更新为a
当该status_div的值是2的时候,更新为b
用一句update可以实现吗??谢谢

更新前
NO   status_div
1               1
1               2
0               1
更新后
NO   status_div
1               a
1               b
0               1

NO值为0的,不更新,
请高手指点,谢谢。

------解决方案--------------------
sorry,写得不够严谨,更改一下,

declare @t table (no int,status_div varchar(3))
insert into @t select 1, '1 '
union all select 1, '2 '
union all select 0, '1 '
union all select 1, '4 '

update @t set status_div= case status_div when '1 ' then 'a ' when '2 ' then 'b ' else status_div end
where no <> 0
select * from @t
--
/*
no status_div
----------- ----------
1 a
1 b
0 1
1 4

(所影响的行数为 4 行)
*/