Wednesday 15 January 2014

Creating Sequence in Sql Server -


I want to create a sequence of numbers in SQL Server which will have a minimum value and maximum value. If the number reaches the maximum limit then I want to cycle. Can any body help me?

There is no need to loop for a while. First of all, you need a table or a table of numbers. :

  Create a table dbo. Go with the money as numbers (not price difference zero primary key cluster) (select Row_Number () over (command S1.object_id) as sys.column from ss cross form sys.columns s2 as num) Insert dbo.Numbers (value) Select the number from Num where num & lt; = 100000  

I just put one 100K You can need more on the number of numbers in my table, you only have to populate this table once. Now you want any sequence can do. Value like this:

  Select from value dbo.Numbers where the value of @ start and @End  

want an increase value ?:

  Select value from dbo.Numbers where the value% @ increment = 0  

No comments:

Post a Comment