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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks,
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