sqlserver如何实现分页的方法实例分析

我还是喜欢你,像日月星辰,经久不息。仲夏时节,气候宜人,大地散发着诱人的清香。五彩斑斓的蝴蝶丰容靓饰,顾盼生姿,体态轻盈的蜜蜂乱欢飞舞,寻香弄绿,一派繁忙的景象。

本文实例讲述了sql server实现分页的方法。分享给大家供大家参考,具体如下:

declare @index int,@num int
set @index = 1--当前页
set @num = 2--单页包含的行数
--分页1
select top (@num) *
from ppohd
where doccode not in
(
  select top (@num * (@index -1)) doccode
  from ppohd
  order by doccode
)
order by doccode
--分页2
select top (@num) *
from ppohd
where doccode >=
(
  select max(doccode)
  from
  (
    select top (@num * (@index - 1) + 1) doccode
    from ppohd
    order by doccode
  ) as tb
)
--分页3
select top (@num) *
from
(
  select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,*
  from ppohd
) as tb
where tb.sno >= @num * (@index - 1) + 1
--分页4
select *
from
(
  select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,*
  from ppohd
) as tb
where tb.sno between (@num * (@index - 1) + 1) and (@num * @index)

希望本文所述对大家SQL Server数据库程序设计有所帮助。

以上就是sqlserver如何实现分页的方法实例分析。爱你们已经两年了,希望我们能走得更久,都好好过日子,加油,要幸福哦。更多关于sqlserver如何实现分页的方法实例分析请关注haodaima.com其它相关文章!

标签: 分页 如何实现