输入banner图图片脚本导航/分类

SQL Server中【case...end】的用法

select CName,头衔=case 2 when CLevel=A1 then 初级程序员 3 when CLevel=A2 then 中级程序员 4 when CLevel=A3 then 高级程序员 5 else 骨灰级大师 6 end 7 from Coder

这种写法可以用来做区间或等值的判断。

  2、相当于C#中的switch...case,例:

1 select CName,头衔=case CLevel
2                 when A1 then 初级程序员
3                 when A2 then 中级程序员
4                 when A3 then 高级程序员
5                 else 骨灰级大师
6             end
7 from Coder

这种写法只能用来做等值的判断。

注意事项:在 case...end 语句中,then后面值的数据类型必须保持一致。

SQL Server中【case...end】的用法

标签:数据   高级程序员   ...   用法   初级程序员   color   程序员   rom   str