Header Ads Widget

Responsive Advertisement

While Loop in SQL Server Database (Database Programming)




While Loop:


Description:

                        Repetition of statement under a specific condition is called while loop.
All loops involve three things common. 
  1. Initialization of variable (Declare Variable / Start Point of Loop)
  2. Set Condition (Control Repetition)
  3. Increment / Decrement 

Example:

Print the numbers from 0 to 10 using while loop in SQL Server Database.


DECLARE @VAR INT; 

SET @VAR=0;     

WHILE @VAR<=10   
BEGIN
PRINT CONCAT('Value is =',@VAR);
SET @VAR=@VAR+1;
END;

Results:



Post a Comment

0 Comments