首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

update的有关问题,

2012-03-30 
update的问题,在线等,急!!表中有一个status_div值,我想做的是,当该status_div的值是1的时候,更新为a当该st

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 行)
*/

热点排行
Bad Request.