while loop with counter : While « Transact SQL « SQL Server / T-SQL






while loop with counter

 


28> CREATE TABLE newtable (a int)
29> GO
1> INSERT INTO newtable VALUES (10)
2> INSERT INTO newtable VALUES (20)
3> INSERT INTO newtable VALUES (30)
4> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)
1> DECLARE @counter int
2> SET @counter = 1
3> WHILE @counter < 1000 BEGIN
4>     UPDATE newtable SET a = a + 1
5>     SET @counter = @counter + 1
6> END
7> GO
1>
2> drop table newtable;
3> GO

 








Related examples in the same category

1.Looping with the WHILE Statement
2.While Loop Demo
3.Use while loop to insert data
4.While with aggregate function