Home > DeveloperSection > Forums > WHILE LOOP IN SQL SERVER
Ankit Singh

Total Post:341

Points:2389
Posted on    December-15-2015 9:41 PM

 Database SQL Server  SQL  SQL Server 2008  SQL Server 2012 
Ratings:


 1 Reply(s)
 390  View(s)
Rate this:
 I want to use While Loop in Sql Server please help me


aditya kumar Patel

Total Post:250

Points:1782
Posted on    December-15-2015 9:46 PM

A while loop will check the condition first and then executes the block of Sql Statements within it as along as the condition evaluates to true.
Syntax:
WHILE Condition
BEGIN
Sql Statemen

DECLARE @site_val INT;

SET @site_val = 0;

WHILE @site_val <= 10

BEGIN

PRINT 'Inside WHILE LOOP ON Mindstick.com';

SET @site_val = @site_val + 1;

END;

PRINT '_________________________________';

PRINT 'Done WHILE LOOP ON Mindstick.com';

PRINT '_________________________________';

GO

 


Don't want to miss updates? Please click the below button!

Follow MindStick