sql-逻辑循环while if

 --计算1-100的和
  declare @int int=1;
  declare @total int=0;
  while(@int<=100)
  begin
  set @total=@total+@int;
  set @int=@int +1;
  end
  select @total
  --计算1-100偶数的和
  declare @index int;
  declare @sum int;
  set @index=1;
  set @sum=0;
  while(@index<=100)
  begin
  if(@index%2=0)
  begin
  set @sum=@sum+@index
  end
  set @index=@index+1;
  end
  select @sum;

  

posted @ 2015-04-17 14:13  馒头的梦想  阅读(309)  评论(0编辑  收藏  举报