declare @Row1 int
declare @row2 int
select @Row1 = 10, @Row2 = 20declare @sql varchar(7000)
select @sql = "select top " + Cast((@Row2-@Row1) as varchar(10)) +
" * from (select top " + Cast(@Row2 as varchar(10)) + " from t1 order by f1) t
order by f1 desc "Exec(@sql)
declare @row2 int
select @Row1 = 10, @Row2 = 20declare @sql varchar(7000)
select @sql = "select top " + Cast((@Row2-@Row1) as varchar(10)) +
" * from (select top " + Cast(@Row2 as varchar(10)) + " from t1 order by f1) t
order by f1 desc "Exec(@sql)
Select Col1,col2,col3 ... from #Tmp where RowID between @XX and @YY
用:
select top xx2 * from tb
where 关键字段 not in (select top xx1 关键字段 from tb)其中:
关键字段就是你表中值唯一的字段,只需要不重复就行了,不管是什么.
这个语句是从第:xx1+1 条记录开始,共取 xx2 条记录
select top 10 * from tb
where 关键字段 not in (select top 14 关键字段 from tb)如果你的表中连这种字段都没有,就只好用:
select identity(int,1,1) ID, t.* into #tmp From tb
select * from #tmp where ID between 15 and 20