The while method of mssql loop record

1. Define variables

Declare @i Int

 

2. Get a single record

Select @i= Min ([id]) From [database name] Where <search condition>

 

3. While loop

While @i Is Not Null

  Begin

  <executive part>

  /* Refetch i until there are no records */

  Select @i=Min([id]) From [database name] Where <!Search conditions> And  [id]>@i

End

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324767753&siteId=291194637