How to generate a range of numbers between two numbers?

后端 未结 30 2281
执念已碎
执念已碎 2020-11-22 10:16

I have two numbers as input from the user, like for example 1000 and 1050.

How do I generate the numbers between these two numbers, using

30条回答
  •  臣服心动
    2020-11-22 10:31

    The best way is using recursive ctes.

    declare @initial as int = 1000;
    declare @final as int =1050;
    
    with cte_n as (
        select @initial as contador
        union all
        select contador+1 from cte_n 
        where contador <@final
    ) select * from cte_n option (maxrecursion 0)
    

    saludos.

提交回复
热议问题