假设你的表名为:tt
declare @tt table (id int identity(1,1),A int null,B datetime null)
declare @tm table (A int null,B datetime null)
insert into @tt select * from tt
declare @m as int,@count as int
set @m=1 //设置初值,这里是从1开始
select @count=count(*) from @tt
while @m<=@count
begin
insert into @tm select a,b from @tt where id=@m
set @m=@m+5
end
select * from tt
select * from @tm
declare @tt table (id int identity(1,1),A int null,B datetime null)
declare @tm table (A int null,B datetime null)
insert into @tt select * from tt
declare @m as int,@count as int
set @m=1 //设置初值,这里是从1开始
select @count=count(*) from @tt
while @m<=@count
begin
insert into @tm select a,b from @tt where id=@m
set @m=@m+5
end
select * from tt
select * from @tm
select a,b from #tmp where x%5=0
这样只能取记录 5,10,15,20... 不能任意确定从哪条记录开始。
不过思路新颖,学习!可以改成
select identity(int,1,1) as x,a , b into #tmp from table1 order by b
select a,b from #tmp where x>=m and (x + n)% 5=0
--m,n为数字(m设为5的倍数或零,0=< n<= 4)
n 初值
n=0 m ---->(m=0时除外)
n=1 m+4
n=2 m+3
n=3 m+2
n=4 m+1