Monday, 24 October 2016

SQL - While Loop Syntax

Below is the WHILE LOOP Syntax in SQL

DECLARE @cnt INT = 1;

WHILE @cnt BETWEEN 1 AND 20
BEGIN

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

END

SQL Doesn't have For Loop, instead you have to use While loop.

No comments:

Post a Comment