欢迎来HKING的博客
起步在ASP.NET的路上,追求属于自己的天空

比较万能的分页:

SQL代码:

 

1 select top 每页显示的记录数 * from topic where id not in
2  (select top (当前的页数-1)×每页显示的记录数 id from topic order by id desc)
3  order by id desc

 

需要注意的是在access中不能是top 0,所以如果数据只有一页的话就得做判断了。。

SQL2005中的分页代码:

SQL代码:

 

1 with temptbl as (
2   SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row, 
3   ...
4 )
5 SELECT * FROM temptbl where Row between @startIndex and @endIndex

 

ROW_NUMBER() 在SQL Server2005以上的版本中才有

posted on 2010-01-08 17:13  HKINGH  阅读(117)  评论(0编辑  收藏  举报