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

 

posted @ 2018-04-24 10:45  1024记忆  阅读(1078)  评论(0)    收藏  举报