Monday, 24 October 2016

SQL - For Loop Syntax

SQL doesn't have For Loop, instead you have to use While loop.
The syntax is as below.


DECLARE @cnt INT = 1;

WHILE @cnt BETWEEN 1 AND 20
BEGIN

PRINT @cnt;
SET @cnt = @cnt+1;

END


No comments:

Post a comment