if else
declare @name int =1
select @name =COUNT (id) from Students
if(@name>10)
begin
print '人好多啊'
end
else
begin
print '人好少啊'
end
--------------------------------
if((select COUNT (id) from Students) >10) --表达式可以是一个返回一行一列的结果集
begin
print '人好多啊'
end
else
begin
print '人好少啊'
end
---------------------------------
--循环1-100,判断是否为奇数,是就加起来
declare @numc int =1
declare @sumnum int =0
while(@numc<=100)
begin
if(@numc %2=1)
begin
set @sumnum =@sumnum +@numc
end
else
begin
set @numc =@numc +1
end
end
print @sumnum