I have a table that holds IDs and count. I want to repeat the rows the number of times mentioned in the count.
My table:
Desired output:
My code:
create table #temp1(CID int, CVID int, count int)
insert #temp1
values
(9906, 4687, 4),
(9906, 4693, 5)
create table #temp2 (CID int,CVID int, count int,ro int)
;with t3 as (
select c.CID,c.CVID, c.count, row_number() over (partition by c.CID order by c.CID) ro
from #temp1 c
)
insert #temp2
select CID,CVID,count,ro from t3 where ro <= count
My code is missing something that its not producing desired result. Any help?!