欢迎光临
我们一直在努力

一个高效的数据分页的存储过程-ASP教程,ASP应用

建站超值云服务器,限时71元/月

create procedure pagetest  –用于翻页的测试
–需要把排序字段放在第一列

 (
  @firstid nvarchar(20)=null,  –当前页面里的第一条记录的排序字段的值
  @lastid nvarchar(20)=null,  –当前页面里的最后一条记录的排序字段的值
  @isnext bit=null,    –true 1 :下一页;false 0:上一页
  @allcount int output,   –返回总记录数
  @pagesize int output,   –返回一页的记录数
  @curpage int     –页号(第几页)0:第一页;-1最后一页。
  )

as

if @curpage=0
 begin
  –统计总记录数
  select @allcount=count(productid) from product_test
  
  set @pagesize=10
  –返回第一页的数据
  select top 10
   productid,
   productname,
   introduction  
   from product_test order by productid
 end

else if @curpage=-1

 select * from
  (select top 10 productid,
   productname,
   introduction

  from product_test order by productid desc ) as aa 
  order by productid
else

 begin
  if @isnext=1
   –翻到下一页
   select top 10 productid,
   productname,
   introduction
  from product_test where productid > @lastid order by productid
  
  
  else
   –翻到上一页
   select * from
    (select top 10 productid,
   productname,
   introduction
  from product_test where productid < @firstid  order by productid desc) as bb order by productid
 end
 

百万数据翻页就像100条数据一样!

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个高效的数据分页的存储过程-ASP教程,ASP应用
分享到: 更多 (0)