笔记5 T-SQL技巧case when then end的update语句


笔记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 */

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM