--可以先建一個虛擬表帶有自動增1的字段如下
crete table tablename(a varchar(20),b int )
select identity(int,1,1) ID,* into #temp from tablename
select top 0 * into #temp1 from tablename
读表A 的 第10-20条记录
select A.a,A.b from #temp A
where A.ID between 10 and 20如每隔5条记录读其中的一条
declare @ipos int
declare @count int
set @ipos=0
select @count=count(*)/5 from tablename
while @count>0
begin
insert into #temp1
select A.a,A.b from #temp A where A.ID=@ipos
set @ipos=ipos+5
@count=@count-1
end
go
select * from #temp1