我會使用CTE遞迴 去完成
;WITH CTE AS (
SELECT col1,1 start,col2
FROM T
UNION ALL
SELECT col1,start+1,col2
FROM CTE
WHERE start + 1 <= col2
)
SELECT col1 as '名稱',1 as '數量'
FROM CTE
這樣?
declare @tab table(
aa nvarchar(50)
,bb int
)
insert into @tab
values('AA 筆',5)
,('AB 紙',5)
select aa
,1 as bb
from @tab
,(
select Row_Number()Over(order by [number]) as Sort
from master..spt_values
) as k
where Sort <= bb