Search notes:

SQL Server T-SQL: while statement

The while statement allows to iterate over a statement (or a block of statements that is enclosed between begin … end) until a certain condition becomes false:
declare
   @i integer = 0;

while @i < 10 begin
   print('i = ' + ltrim(str(@i)));
   set @i = @i + 1;
end;
Github repository about-MSSQL, path: /t-sql/statements/while/counter.sql

See also

T-SQL statements

Index