declare @Clx table(id int identity,duan int,bu int,bu1 int,bu2 int,bu3 int)
declare @ceng int
[email protected]
declare @c45 int
[email protected] [email protected](@c45 值为0、1、2、3、4五者之一)
[email protected]=0,不用处理
[email protected]=1,[email protected]+1,列bu1的值+1
[email protected]=2,[email protected]+1,列bu2的值+1
[email protected]=3,[email protected]+1,列bu3的值+1
[email protected]=4,[email protected]+1
---
请教一个不使用if,只使用case的sql代码?
------解决方案--------------------
update @Clx set bu=case when @c45> 0 and @c45 <4 then bu+1 else bu end,
bu1=case @c45 when 1 then bu1+1 else bu1 end,
bu2=case @c45 when 2 then bu2+1 else bu2 end,
bu3=case @c45 when 3 then bu3+1 else bu3 end,
duan=case @c45 when 4 then duan+1 else duan end
where [email protected]