How to apply WHILE loop with simple examples in SQL server. I want to insert data in table using loops.
home / developersection / forums / how to apply while loop with simple examples in sql server?
How to apply WHILE loop with simple examples in SQL server. I want to insert data in table using loops.
Amrita Bhattacharjee
08-Feb-2023Above is an example of using WHILE loop in SQL whereas the loop will print the numbers 1 to 20. DECLARE statement here initializes the counter variable. PRINT statement is used to give the output value of the counter which is based on the condition that if the condition is true then only the PRINT statement will give the counter variable value as output. SET statement is used for incrementing the value of counter variable by 1 and the above loop will continue until the value of counter variable meets equal or less than 20 or else until the condition becomes false to end the whole process.