mssql循环记录之while方法

1、定义变量

Declare @i Int

2、获取单条记录

Select @i=Min([id]) From [数据库名] Where <检索条件>

3、While循环

While @i Is Not Null

  Begin

  <执行部份>

  /*重新获取i,直到没有记录*/

  Select @i=Min([id]) From [数据库名] Where <!检索条件> And [id]>@i

End

猜你喜欢

转载自www.cnblogs.com/wm218/p/8926783.html