tags:

views:

48

answers:

4

I want to make propotion codes for my product.

I have created an appropriate SQL statement which basically uses the current timestamp and runs SHA1 on it.

I tried a while ago to create an iterative loop over my INSERT command but failed

anyone know how?

Do 50 times
   INSERT INTO ......
end

Also, I cannot have two of the same promotion code so the timestamp needs to be different for each iteration (If it is at all possible that the timestamp might be the same between iterations).

A: 

write the code in python or some other scripting language. Use a GUID for the promotion code rather than a hash of the timestamp.

TheSteve0
A: 

http://dev.mysql.com/doc/refman/5.0/en/flow-control-constructs.html

echo
I tried that already, but I would not get it working. I am not so familar with the mySQL syntax
jax
A: 

This is pretty dirty, but if you have any table on your system which you know has more than 50 rows, you can do the following:

create table promotion_code ( pc varchar(100) );
set @c = 1;
insert into promotion_code 
  select sha1( now() + (@c := @c + 1 ) ) 
  from mysql.help_relation limit 50;
Martin
A: 
CREATE PROCEDURE createPromotions(p1 INT)
 BEGIN
   SET @x = 0;
   REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
END

Some sort of proceedure like this would be nice but I don't know how to get it into the format I need. which is to repeat an SQL statement 50 times

jax