本文实例讲述了sqlserver实现分页的方法。分享给大家供大家参考,具体如下:declare@indexint,@numintset@index=1--当前页set@num=2--单页包含的行数--分页1selecttop(@num)*fromppohdwheredoccodenotin(selecttop(@num*(@index-1))doccodefromppohdorderbydoccode)orderbydoccode--分页2selecttop(@num)*fromppohdwheredoccode>=(selectmax(doccode)from(selecttop(@num*(@index-1)+1)doccodefromppohdorderbydoccode)astb)--分页3selecttop(@num)*from(selectppohd.doccodeas'mydoccode',row_number()over(orderbydoccode)assno,*fromppohd)astbwheretb.sno>=@num*(@index-1)+1--分
本文实例讲述了sql server实现分页的方法。分享给大家供大家参考,具体如下:
declare @index int,@num intset @index = 1--当前页set @num = 2--单页包含的行数--分页1select top (@num) *from ppohdwhere doccode not in( select top (@num * (@index -1)) doccode from ppohd order by doccode)order by doccode--分页2select top (@num) *from ppohdwhere doccode >=( select max(doccode) from ( select top (@num * (@index - 1) + 1) doccode from ppohd order by doccode ) as tb)--分页3select top (@num) *from( select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,* from ppohd) as tbwhere tb.sno >= @num * (@index - 1) + 1--分页4select *from( select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,* from ppohd) as tbwhere tb.sno between (@num * (@index - 1) + 1) and (@num * @index)
更多关于SQL Server相关内容感兴趣的读者可查看本站专题:《SQL Server分页技术总结》、《SQL Server查询操作技巧大全》、《SQL Server存储过程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函数汇总》及《SQL Server日期与时间操作技巧总结》
希望本文所述对大家SQL Server数据库程序设计有所帮助。
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!