笔记5 T-SQL技巧case when then end的update语句
1 --T-SQL技巧case when then end的update语句
2 declare @T table (name varchar(1),taici int)
3 insert into @T
4 select 'a',1 union all
5 select 'b',2 union all
6 select 'c',3 union all
7 select 'd',4 union all
8 select 'e',5
9
10 SELECT * FROM @T
11
12 update @T set taici=
13 case when taici=5 then 2
14 when taici<2 then taici
15 when taici>=2 then taici+1
16 when taici=2 then 5 end
17
18 select * from @T order by taici
19 /*
20 name taici
21 ---- -----------
22 a 1
23 e 2
24 b 3
25 c 4
26 d 5
27 */