I need to create a stored procedure to do the following;
SELECT * FROM TABLE1
Then for each row returned;
INSERT INTO TABLE2 (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
How would I go about doing this?
UPDATE **
So based on responses so far I've got the following sql;
INSERT INTO recEntrantStatus (entrantId, roundId, judgeId)
SELECT entrantId, judgeId
FROM recEntrantStatus
WHERE roundId = 0
AND voted = true
AND enterNextround = true
But I need to add a fixed value eg an input @round into the newly created records in the column roundId.
How do I go about doing that?
Thanks.
------------------------------------- UPDATE 2 -------------------------------------------
So thanks to some significant help from you guys, I've now got the following SQL which works great at this stage:
INSERT INTO recEntrantStatus (entrantId, roundId, judgeId, notified, voted, enterNextRound)
SELECT entrantId, (@round + 1), judgeId, 0, 0, 0
FROM recEntrantStatus
WHERE roundId = @round
AND voted = 1
AND enterNextround = 1
This code checks for all records where 'enterNextRound' is true, and then creates a new record for each of them.
However, I now need to expand this so that:
A) Check a second table(tblJudges) for all judges and get an array of all the judges Id's (Id)
B) Do the same as in the above example except now creating each of the above records for each of the judges / judges Id's obtained from step A.
Any help / suggestions would as always be greatly appreciated.
Thanks!
CLOSED - Question posted as a new question due to additional requirements. Thanks!
INSERT INTO recEntrantStatus (entrantId, roundId, judgeId) SELECT entrantId, @round, judgeId FROM ...