查询10到20行的数据



1、
 alter table tablename add id int identity(1,1)

 select * from tablename where id>=10 and id<=20

 alter table tablename drop id
2、用存储过程
 create proc pageSelectTest
 (
  @intN int,
  @intM int
 )
 as
 set nocount on
 declare @intRowCount int
 declare @strSql nvarchar(200)
 set @intRowCount=@intM-@intN+1

 select identity(int,0,1) as id,表名.* into #temp from 表名

 set @strSql='select top  '+cast(@intRowCount as nvarchar(10))+' *from #temp' +
     ' where id not in ( select top '+ cast((@intN-1) as nvarchar(10)) +' id from #temp)'

 exec sp_ExecuteSql @strSql
 go
3、
 此语句的缺点是字段名中的数据不能有重复的。
 select top 20 * from tablName where 字段名 not in(select top 10 字段名 From tableName)

能力有限,只能想这么多了,呵呵

posted on 2005-10-10 10:55  冷月孤峰  阅读(244)  评论(0)    收藏  举报