--声明两个变量,使用select关键字给变量赋值,值来源自数据表declare @Name nvarchar(50)declare @email nvarchar(50)select @Name = (select clientid from client where clientid = '1'),@email = (select emailfrom client where clientid = '1')print @Nameprint @email--查询出Users表中username列包含"["的记录,使用2种方法select * from Userswhere username like '%\[%' escape '\'select * from Users where username like '%[[]%'--使用IF Else 判断两个数的大小declare @i1 intdeclare @i2 intselect @i1 = 100 ,@i2 = 20if(@i1>@i2)beginprint convert(varchar(50),@i1)+' 比'+convert(varchar(50),@i2)+' 大'end elsebeginprint 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)'endfrom Score--利用循环控制(While,Continue,Break)打印输出以下字符:declare @num intset @num = 0while(@num<100)begin set @num =@num + 1if(@num=6 or @num = 7)continue;if(@num>9)break;print @numend