Sql语句:IF ELSE CASE WHEN WHILE CONTINUE BREAK

--声明两个变量,使用select关键字给变量赋值,值来源自数据表

declare @Name nvarchar(50)
declare @email nvarchar(50)

select @Name = (select clientid from client where clientid = '1'),@email = (select email from client where clientid = '1')

print @Name
print @email

--查询出Users表中username列包含"["的记录,使用2种方法

select * from Users	where username like '%\[%' escape '\'

select * from Users where username like '%[[]%'


--使用IF Else 判断两个数的大小

declare @i1 int
declare @i2 int

select @i1 = 100 ,@i2 = 20

if(@i1>@i2)
begin
print convert(varchar(50),@i1)+' 比'+convert(varchar(50),@i2)+' 大'
end 

else
begin
print convert(varchar(50),@i1)+' 比'+convert(varchar(50),@i2)+' 小'
end

--使用Case When 将Score表中的score_1字段转义输出为

select *,备注 = case 
when score_1<60 then '不及格'
when score_1>=60 and score_1<=80 then '良好'
when score_1>80 and score_1<=100 then '优秀'
else '异常(Error)'
end
from Score


--利用循环控制(While,Continue,Break)打印输出以下字符:

declare @num int

set @num = 0

while(@num<100)
begin 


set @num =@num + 1

if(@num=6 or @num = 7)
continue;

if(@num>9)
break;

print @num

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值