`
wostyh
  • 浏览: 75429 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

SQL分页语句

阅读更多

比较万能的分页:

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

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

 

SQL2005中的分页代码:

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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics