Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
spikeic
Starting Member
2 Posts |
Posted - 2004-08-05 : 12:44:07
|
| I'm looking to create a simple table containing the following:Start Stop0 55 1010 1515 20etc...Is there some kind of looping routine to perform n=n+5? I also need some statement to end the loop. For instance, I want to be able to end this table at 1000 and 1005. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-05 : 12:56:49
|
| declare @inc intset @inc = 0declare @inc1 intset @inc1 = 5UPDATE Table1 SET @inc = Start = @inc + 5, @inc1 = Stop = @inc1 + 5it could probably be done with just one variable...Go with the flow & have fun! Else fight the flow :) |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-05 : 12:59:26
|
| Declare @myTable1 table (n int)Insert Into @myTable1Select 0 Union All Select 1 Union All Select 2 Union All Select 3 Union All Select 4 Union All Select 5 Union All Select 6 Union All Select 7 Union All Select 8 Union All Select 9Insert Into @myTable1 Select n=n+(Select max(n)+1 From @myTable1) From @myTable1Insert Into @myTable1 Select n=n+(Select max(n)+1 From @myTable1) From @myTable1Insert Into @myTable1 Select n=n+(Select max(n)+1 From @myTable1) From @myTable1Insert Into @myTable1 Select n=n+(Select max(n)+1 From @myTable1) From @myTable1Insert Into @myTable1 Select n=n+(Select max(n)+1 From @myTable1) From @myTable1Select * From @myTable1Declare @myTable2 table (start int, stop int)Insert Into @myTable2Select Start = 5*n, Stop = 5*(n+1)From @myTable1Select * From @myTable2 Where Start<=1000Corey |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-05 : 13:00:47
|
| Realistically, I have a sequence routine that generates a seq from a A to B stepping by Cso normally I would doSelectStart = number,Stop = number + 5From dbo.getSequence(0,1000,5)Corey |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-05 : 13:03:31
|
| with one variable:declare @inc intset @inc = -5 -- if you want to start with 0, it's 0 if you want to start with 5UPDATE #tempSET @inc = Start = (@inc + 5), Stop = (@inc + 5)Go with the flow & have fun! Else fight the flow :) |
 |
|
|
|
|
|