Jun 2, 2003 #1 meckeard Programmer Aug 17, 2001 619 US Hi Gang, I need to do some quick and dirty inserts into a table. What's the best way to do it in SQL w/o manually inserting each record? Is there a loop statement that would work? Or do I need to use a cursor? Thanks, Mark
Hi Gang, I need to do some quick and dirty inserts into a table. What's the best way to do it in SQL w/o manually inserting each record? Is there a loop statement that would work? Or do I need to use a cursor? Thanks, Mark
Jun 2, 2003 #2 SonOfEmidec1100 Technical User Aug 12, 2001 965 AU Whats the source of the rows you are inserting ? If you are selecting from another table you should be able to use something along the lines INSERT INTO MyTable SELECT field1,field2 FROM MyTable2 Upvote 0 Downvote
Whats the source of the rows you are inserting ? If you are selecting from another table you should be able to use something along the lines INSERT INTO MyTable SELECT field1,field2 FROM MyTable2
Jun 2, 2003 #3 balor Programmer Jul 24, 2000 74 If you don't have a source and just want to insert some test data you can use WHILE to create a loop. Example: DECLARE @nNrOfRows int, @nRow int SET @nNrOfRows = 100 SET @nRow = 0 WHILE(@nNrOfRows > @nRow) BEGIN INSERT INTO ... SET @nRow = @nRow + 1 END Upvote 0 Downvote
If you don't have a source and just want to insert some test data you can use WHILE to create a loop. Example: DECLARE @nNrOfRows int, @nRow int SET @nNrOfRows = 100 SET @nRow = 0 WHILE(@nNrOfRows > @nRow) BEGIN INSERT INTO ... SET @nRow = @nRow + 1 END