--while循环计算1到100的和 declare @a int declare @sum int set @a=1 set @sum=0 while @a<=100 begin set @sum+=@a set @a+=1 end print @sum
--if,else条件分支
if(1+1=2) begin print '对' end else begin print '错' end --when then条件分支 declare @today int declare @week nvarchar(3) set @today=3 set @week=case when @today=1 then '星期一' when @today=2 then '星期二' when @today=3 then '星期三' when @today=4 then '星期四' when @today=5 then '星期五' when @today=6 then '星期六' when @today=7 then '星期日' else '值错误' end print @week