No need for a while loop. First, you need a Tally or Numbers table:
Create Table dbo.Numbers ( Value int not null Primary Key Clustered )
GO
With Nums As
(
Select Row_Number() Over( Order By S1.object_id ) As Num
From sys.columns as s1
cross join sys.columns as s2
)
Insert dbo.Numbers( Value )
Select Num
From Nums
Where Num <= 100000
I put only 100 thousand numbers in the table, but you may need more. You only need to fill out this table once. Now you can create any sequence you want. For example:
Select Value
From dbo.Numbers
Where Value Between @Start And @End
Want to get the increment value ?:
Select Value
From dbo.Numbers
Where Value % @Increment = 0
source
share