1

I want to grab a variable (between 1-365) and use this value to create the number of empty rows in a table:

insert into tblCustomer (ID) values (), (), ();

is there an easier way to do this or is using a loop the best way?

Any help would be appreciated.

nads
  • 407
  • 5
  • 9

1 Answers1

2

A procedure with an IN parameter is quite easy

 DELIMITER $$
 DROP PROCEDURE IF EXISTS test_loop$$
 CREATE PROCEDURE test_loop(IN number INT)
 BEGIN
 DECLARE x  INT(11);

 SET x = 1;    

 WHILE x  <= number  DO
 INSERT INTO tblCustomer(id)  VALUES('');
 SET  x = x + 1; 
 END WHILE;

 END$$
DELIMITER ;

How to use it

CALL test_loop(20);
Mihai
  • 26,325
  • 7
  • 66
  • 81