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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 loop in sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-13 : 08:28:05
Kim writes "I have a 319 records in sql database, how do you select records starting from 1 thru 319 increment by 30. For ex. select record 1, 31, 61, 91 .... And put all this selected records in a new table with record 1, 31, 61 ....

Thanks"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-13 : 09:05:26
this should do:

declare @MyTable table(id int identity, OrderId int)
insert into @MyTable(orderid)
select orderid from orders

select *
from @MyTable
where (id-1)%30 = 0


Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -