Microsoft SQL Server Using While loop


Example

The WHILE loop can be used as an alternative to CURSORS. The following example will print numbers from 0 to 99.

 DECLARE @i int = 0;
 WHILE(@i < 100)
 BEGIN
    PRINT @i;
    SET @i = @i+1
 END