I would like to insert a value retrieved from a counter in SQL and repeat it 300 times.
Something like:
DECLARE @Counter = 0;
-- BEGIN Loop
SET @Counter = @Counter + 1
INSERT INTO tblFoo VALUES(@Counter)
-- REPEAT 300 times
How can I achieve this? Thanks
I would prevent loops in general if i can, set approaches are much more efficient:
Demo
Generate a set or sequence without loops
In ssms we can use GO to execute same statement
Edit This mean if you put
Some query will be executed n times
Found some different answers that I combined to solve simulair problem:
Adds 1 miljon rows with
You may try it like this: