declare @SQLStr varchar(8000) set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )' exec(@SQLStr)
select top I-n * from #temp where id not in (select top n id from #temp)
use master go create database te go use te go create table temp_temp (tt int, rr int) go declare @i integer select @i=1 while @i<21 begin insert into temp_temp values(@i,20-@i) select @i=@i+1 end go SELECT Top 5 * FROM temp_temp WHERE tt NOT IN (SELECT TOP 10 tt from temp_temp )将5换成m-n+1 10换成m m>n 本例为取出第11--15条记录 n--m
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )'
exec(@SQLStr)
go
create database te
go
use te
go
create table temp_temp
(tt int,
rr int)
go
declare @i integer
select @i=1
while @i<21
begin
insert into temp_temp values(@i,20-@i)
select @i=@i+1
end
go
SELECT Top 5 * FROM temp_temp WHERE tt NOT IN (SELECT TOP
10 tt from temp_temp )将5换成m-n+1 10换成m m>n
本例为取出第11--15条记录 n--m