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