How to generate a range of numbers between two numbers?

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

    2 years later, but I found I had the same issue. Here is how I solved it. (edited to include parameters)

    DECLARE @Start INT, @End INT
    SET @Start = 1000
    SET @End = 1050
    
    SELECT  TOP (@End - @Start+1) ROW_NUMBER() OVER (ORDER BY S.[object_id])+(@Start - 1) [Numbers]
    FROM    sys.all_objects S WITH (NOLOCK)
    

提交回复
热议问题