Steve,

In order to do this with one SQL command you would need a table of numbers from 
1 to whatever you think would be the largest Qty ever entered.
Let's call the table AllNumbers
It has one column OneNumber INT
Use a loop to fill it with numbers from 1 to 1 million.
Index the OneNumber Column

Now you can say
INSERT into TableDetail (HeaderID,RecordID,ItemID,ColorCD) +
Select HeaderID,OneNumber,ItemID,ColorCD +
>From TableHeader t1, AllNumbers T2 +
WHERE T2.OneNumber <= T1.QTY


Dennis McGrath


________________________________
From: [email protected] [mailto:[email protected]] On Behalf Of Wills, Steve
Sent: Wednesday, October 28, 2009 9:42 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Iterating Inserts - Header/Summary => Details?

I have a table that is more-or-less a header/parent/summary table.  It contains 
a column-value for quantity.  I would like to use that quantity to insert that 
quantity of records into a detail table.

For example:

MY_PSEUDO_HEADER
================
HeaderID  ItemID  ColorCD   QTY
--------  ------  -------  -----
   00410     ABC       RD      5
   07045     ABC       WH     50
   94321     DEF       BL    100
   94322     DEF       RD     33
   57058     XYZ       BK     47

MY_PSEUDO_DETAIL
================
HeaderID  RecordID  ItemID  ColorCD
--------  --------  ------  -------
   00410         1     ABC       RD
   00410         2     ABC       RD
   00410         3     ABC       RD
   00410         4     ABC       RD
   00410         5     ABC       RD
-- And so on ...

Would anyone have any tips on a good way to do this, preferably but not 
necessarily via "straight" SQL, rather than a WHILE-Loop, Cursor, Etc?

Thanks,
Steve (Still Around) in Memphis


Reply via email to