Link to home
Start Free TrialLog in
Avatar of sopheak
sopheak

asked on

Multiply a record based on a field?

I have table1 with 2 columns (FruitName, Qty) see the sample data.

FruitName      Qty
Apple             4
Orange          2

I need a way to insert the above data into table2 (FruitName, Qty) so that the quantity equates to a record.  So, in the case of Apple with the quantity of 4, I need table2 to have 4 records for apple, with the updated qty of 1.

FruitName      Qty
Apple             1
Apple             1
Apple             1
Apple             1
Orange          1
Orange          1

thanks,
sopheak




Avatar of chiragkhabaria
chiragkhabaria

Insert Into Table2 (Fruitname,Qty)
Select FruitName, 1 From YourTable t
inner join
(
Select Distinct  Number From Master..spt_values
Where Number >0
) as  i
on t.qty >= i.number
ASKER CERTIFIED SOLUTION
Avatar of bamboo7431
bamboo7431

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sopheak

ASKER

thanks,