What is the syntax of a for loop in TSQL?
Simple answer is NO !!.
There is no
FORin SQL, But you can useWHILEorGOTOto achieve the way how theFORwill work.
WHILE :
DECLARE @a INT = 10
WHILE @a <= 20
BEGIN
PRINT @a
SET @a = @a + 1
END
GOTO :
DECLARE @a INT = 10
a:
PRINT @a
SET @a = @a + 1
IF @a < = 20
BEGIN
GOTO a
END
I always prefer WHILE over GOTO statement.