写的很好,转过来收藏
执行顺序是 – 从上至下 – 从左至右 --,所当上一个条件满足时(无论下面条件是否满足),执行上个条件,当第一个条件不满足,第二个条件满足时,执行第个二条件
IF …BEGIN…(代码块)ENDELSE (注意这里没有ELSE IF,要实现只能在下面的块中用IF判断)BEGIN…(代码块)END
列:
declare @num int --定义变量set @num=1 --赋值变量if(@num>10)beginselect * from 表1endelsebeginif(@num<0)select Top(20) * from 表2elseprint @numend
CASE …WHEN … (条件/代码块) THEN …(返回值/case when then else end)ELSE …(可省略)END
列:
declare @num int --定义变量set @num=111 --赋值变量select @num,casewhen @num<=100 then casewhen @num>=80 then ‘A’when @num>=60 then ‘B’else ‘C’ endwhen @num>=200 then ‘优秀’else ‘haha’end
————————————————
版权声明:本文为CSDN博主「我家喵叫长生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:[https://blog.csdn.net/weixin_43488965/java/article/details/89922467]