declare @S smallint,@I smallint,@NUMS smallint
set @S=0 --總和
set @I=1 --從1開始
set @NUMS=0 --個數默認為0個
while(@I<=100) --循環
begin
if(@I%3=0)
begin
set @S=@S+@I --總和 --當@I某個數符合時,就是加它,即得這些數的總和
set @NUMS=@NUMS+1 --如果條件符合個數就自動加班
end
set @I=@I+1 --循環加值
end
print @S --輸出總和 1683
print @NUMS --輸出總個數 33