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
5条答案
按热度按时间cbwuti441#
You may try it like this:
5f0d552i2#
brjng4g33#
I would prevent loops in general if i can, set approaches are much more efficient:
Demo
Generate a set or sequence without loops
33qvvth14#
In ssms we can use GO to execute same statement
Edit This mean if you put
Some query will be executed n times
ovfsdjhp5#
Found some different answers that I combined to solve similar problem:
Adds 1 million rows with