How to generate a range of numbers between two numbers?

后端 未结 30 1906
执念已碎
执念已碎 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:19

    The best option I have used is as follows:

    DECLARE @min bigint, @max bigint
    SELECT @Min=919859000000 ,@Max=919859999999
    
    SELECT TOP (@Max-@Min+1) @Min-1+row_number() over(order by t1.number) as N
    FROM master..spt_values t1 
        CROSS JOIN master..spt_values t2
    

    I have generated millions of records using this and it works perfect.

提交回复
热议问题