I’ve got a table that resembles this:
id
name
datetime
quantity
and I’d like to, with SQL, move these records from one table to another that will not have the quantity column, inserting record X times where X is the value of quantity so ….
id name datetime quantity
----------------------------------
5 book-order 15-Mar-2010 3
# becomes
id name datetime
------------------------
5 book-order 15-Mar-2010
6 book-order 15-Mar-2010
7 book-order 15-Mar-2010
Is there a way to do this in pure SQL?
Here is a way to do it, assuming that quantity is no more than 100:
The hard part is generating a numbers table, if the quantity gets too big.