I was wondering how long it would take you to reply! Good to see you’re still here.
Yes, I do want to return hundreds of thousand copies of the same row if that is what was sold. I need to take the data from the sales system and insert it into a customer support system. If a quantity of 10 products was sold then there should be 10 individual items in the support system that will then have further date populated from other sources, such as serial numbers, location data, etc. The same applies if quantity is 2 or 10,000 (probably a more realistic maximum at the moment). The company only cares about quantity at the sales level, but support has to know every single item
Thank you for the suggestions swampBoogie. Unfortunately, the value of quantity could be in the thousands or even the hundreds of thousands which makes it difficult
I am integrating various systems at the database layer. There is no server-side language involved unfortunately
declare @T as table
(
ID int,
Quantity int,
Product char(50) null
)
declare @TOUT as table
(
ID int,
Product char(50) null
)
insert into @T values(1,2,'Widget')
insert into @T values(2,3,'Fnacy Widget')
select * from @T
Declare @nextID int
Declare @quantity int
Declare @I int
Select @nextID=0
While 1=1
begin
Select @NextID=(select min(ID) from @T where ID>@nextId)
Select @quantity=(select min(Quantity) from @T where ID=@nextId)
if @nextId is null
break
else
set @I=0
while @I<@quantity
begin
insert into @TOUT(ID,Product)
select ID,Product from @T where ID=@nextID
set @I=@I +1
end
continue
end
select *
from @TOUT