导航:业界 | 认证 | 工具 | 图形 | 技术 | 系统 | 网络 | 办公 | 网页 | 文摘 | 动画
您当前的位置:diva8.com -> I T -> 技术 -> ASP学院 -> I T内容
栏目导航
· .Net专栏 · Script
· ASP学院 · PHP学院
· Web服务器 · CGI学院
· XML学院 · SQL学院
· JSP学院 · SMS学院
热门I T
· [组图] 音频后期处理Adobe ...
· [组图] Photoshop--照片处理...
· [组图] 廉颇老矣?IE7.0 Bet...
· [图文] DuDu下载加速器推出...
· [组图] 清晰还原!Photoshop...
· [组图] 用photoshop给图片祛...
· [组图] DuDu 下载加速器试用...
· [组图] 新春特别版:PPLIVE...
· [图文] 让查找更方便些 腾讯...
· [组图] 廉颇老矣?IE7.0 Bet...
相关I T
· asp+sqlserver 分页...
· 利用SQLSERVER存储过...
· 学会在ASP中使用存储...
· SQL Server 存储过程...
· 用存储过程实现ASP对...
· ASP.NET中利用存储过...
· SQL存储过程在.NET数...
· 使用链接服务器执行...
· select用存储过程返...
· ASP调用ORACLE存储过...
一个高效的数据分页的存储过程
作者:admin  来源:齐昌网络  发布时间:2004-12-13 15:41:21  发布人:qichang

减小字体 增大字体


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条数据一样!



[] [返回上一页] [打 印] [收 藏]
∷相关I T评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 在线人数:
diva8.com Copyright © 2001-2006 diva8.com All Rights Reserved .粤ICP备05014750号