分页存储过程(用存储过程实现数据库的分页代码)

时间:2024-01-20 05:22:57 


--*******************************************************
--* 分页存储过程 *
--* 撒哈拉大森林 *
--* 2010-6-28 *
--*******************************************************

if exists(select * from sysobjects where type='P' and name=N'P_Paging')
drop procedure P_Paging
go

create procedure P_Paging
@SqlStr nvarchar(4000), --查询字符串
@CurrentPage int, --第N页
@PageSize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@SqlStr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@PageSize) as 总页数--,@rowcount as 总行数,@CurrentPage as 当前页
set @CurrentPage=(@CurrentPage-1)*@PageSize+1
exec sp_cursorfetch @P1,16,@CurrentPage,@PageSize
exec sp_cursorclose @P1
set nocount off
go

----创建测试表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
--create table Test_Students(
-- id int IDENTITY(1,1) not null,
-- name nvarchar(100) not null
--)
--
----创建测试数据
--declare @i int
--set @i = 100000
--while @i>0
-- begin
-- insert into Test_Students values('姓名')
-- set @i = @i - 1
-- end
--
----执行存储过程
--exec P_Paging 'select * from Test_Students order by id',100,100 --执行
--
----删除测试表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
标签:分页,存储过程
0
投稿

猜你喜欢

  • Python编程实现的简单神经网络算法示例

    2022-01-06 05:53:17
  • ADO组件之分页程序详解

    2008-10-09 12:28:00
  • pycharm软件实现设置自动保存操作

    2022-09-01 00:02:15
  • 微信小程序实现点击出现弹窗

    2024-04-19 10:14:43
  • 有效网页表单的八条规则[译]

    2009-06-01 10:29:00
  • 如何优化网站图片以快速显示

    2008-04-05 10:09:00
  • 如何远程使用服务器上的Jupyter notebook

    2023-02-08 10:45:54
  • 如何使用微信公众平台开发模式实现多客服

    2023-11-14 17:48:37
  • 详解Go操作supervisor xml rpc接口及注意事项

    2024-05-22 10:30:41
  • SQL Server数据库入门学习总结

    2012-08-21 11:01:33
  • 解决在Python编辑器pycharm中程序run正常debug错误的问题

    2023-09-09 09:58:39
  • Python 多个图同时在不同窗口显示的实现方法

    2022-07-02 01:20:35
  • python如何为创建大量实例节省内存

    2023-03-19 06:35:37
  • 利用JAVA反射,读取数据库表名,自动生成对应实体类的操作

    2024-01-14 23:58:29
  • Javascript:window对象出身何处

    2007-08-28 15:16:00
  • SQL触发器实例讲解

    2024-01-24 13:46:55
  • Python绘制计算机CPU占有率变化的折线图

    2021-08-11 05:50:37
  • Python 实现将大图切片成小图,将小图组合成大图的例子

    2023-05-23 18:08:36
  • 使用python编写一个语音朗读闹钟功能的示例代码

    2021-10-24 13:34:41
  • ASP写的不错的"数字分页"涵数

    2008-10-19 17:21:00
  • asp之家 网络编程 m.aspxhome.com