View Single Post
  #2  
Old 08-28-2011, 05:48 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

Assuming your values are all consecutive. then this seems to work:
Code:
set @listid = 700;
set @start = 219000;
set @end = 219053;
DELETE from goallists where listid = @listid;
DROP PROCEDURE IF EXISTS myProc;
delimiter $$
CREATE PROCEDURE myProc()
DETERMINISTIC
BEGIN
   DECLARE counter INT DEFAULT @start;

   simple_loop: LOOP
     INSERT INTO `goallists` (`listid`, `entry`) VALUES (@listid, counter);
     SET counter=counter+1;
     IF counter>@end THEN
        LEAVE simple_loop;
     END IF;
   END LOOP simple_loop;
   SELECT * from goallists where listid = @listid;
END$$
delimiter ;
call myProc();
Just change the listid, start and end values at the top of the code to what you want.

PS: I had to google for how to do this (I'm not an SQL expert either ), code copied from here: http://www.java2s.com/Code/SQL/Proce...SimpleLOOP.htm

Last edited by Derision; 08-28-2011 at 06:17 PM.. Reason: Moved INSERT before increment / changed end condition
Reply With Quote