筆記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