Generating Rows Based on Column Value

前端 未结 3 465
情书的邮戳
情书的邮戳 2020-12-19 17:15

One of my tables in my database contains rows with requisition numbers and other related info. I am trying to create a second table (populated with an INSERT INTO

3条回答
  •  别那么骄傲
    2020-12-19 17:25

    You need recursive way :

    with t as (
         select Requisition, 1 as start, Quantity
         from table
         union all
         select Requisition, start + 1, Quantity
         from t
         where start < Quantity
     ) 
    select Requisition, Quantity, start as Series  
    from t; 
    

    However, by default it has limited to only 100 Quantities, if you have a more then you need to specify the query hint by using option (maxrecursion 0).

提交回复
热议问题