Syntax of for-loop in SQL Server

Macho picture Macho · May 20, 2011 · Viewed 628.5k times · Source

What is the syntax of a for loop in TSQL?

Answer

TcKs picture TcKs · May 20, 2011

There is no for-loop, only the while-loop:

DECLARE @i int = 0

WHILE @i < 20
BEGIN
    SET @i = @i + 1
    /* do some work */
END