存储过程实现分页

*存储过程

 drop proc  P_LoadPageData

 create Proc P_LoadPageData

--参数

 @pageIndex int,  --第几页

 @pageSize int,    --一页几行

 @total int out as   --总行数

   --代码  

select top(@pageSize)*from dbo.HKSJ_Main where ID not in  (   select top((@pageIndex-1)*@pageSize) ID from dbo.HKSJ_Main order by ID  )  

order by ID  select @total=COUNT('a')from dbo.HKSJ_Main  select @total  

 --理解((@pageIndex-1)*@pageSize  例如,假设查询第3页,每页5行;要显示第3页的所有行,就要先排除前面的(3-1)*5=10条数据。

 --测试存储过程  

declare @total int  

exec P_LoadPageData 3,5,@total out  

print @total    

 

 --越过多少条,去多少条:分页原理。

 select*from dbo.HKSJ_Main  select COUNT(*) from dbo.HKSJ_Main 

--count(*)在所有列中找最简单(计算量)的列进行统计。

    例如char(1)  select COUNT('a') from dbo.HKSJ_Main  --'a'表示:任一,每一。

相当于 *  select COUNT(2) from dbo.HKSJ_Main  --表示以第二列计算列数

 

posted @ 2016-11-07 23:45  hao_1234_1234  阅读(199)  评论(0编辑  收藏  举报