通过while 计算1---100之间奇数的和。
declare @sum int =0
declare @i int =1
while @i<=100
begin
if @i%2<>0
begin
set @[email protected]+@i
end
set @[email protected]+1
end
print @sum
通过while 计算1---100之间偶数的和。
declare @sum1 int =0declare @n int =1
while @n<=100
begin
if @n%2=0
begin
set @[email protected]+@n
end
set @[email protected]+1
end
print @sum1