SQL Server通用分页存储过程:利用SQL Server未公开的存储过程实现
来源:互联网 发布:iphoto mac 破解版 编辑:程序博客网 时间:2024/05/16 04:59
存储过程定义:
CREATE procedure [dbo].[SplitPage]
(
@SelectCommandText nvarchar(4000), -- 要执行的查询命令
@CurrentPageIndex int = 0, -- 当前页的索引,从 0 开始
@PageSize int = 20, -- 每页的记录数
@RowCount int = 0 out, -- 总的记录数
@PageCount int = 0 out -- 总的页数
)
AS
IF @PageSize <= 0
BEGIN
RAISERROR('参数 PageSize 必须大于零。', 16, 1);
RETURN
END
DECLARE @p1 int
DECLARE @RowIndex int
SET @CurrentPageIndex = @CurrentPageIndex + 1
EXEC sp_cursoropen
@p1 output,
@SelectCommandText,
@scrollopt = 1,
@ccopt = 1,
@RowCount = @RowCount output;
SET @PageCount = ceiling(1.0 * @RowCount / @PageSize);
SET @RowIndex = (@CurrentPageIndex - 1) * @PageSize + 1
EXEC sp_cursorfetch
@p1,
16,
@RowIndex,
@PageSize;
EXEC sp_cursorclose
@p1
(
@SelectCommandText nvarchar(4000), -- 要执行的查询命令
@CurrentPageIndex int = 0, -- 当前页的索引,从 0 开始
@PageSize int = 20, -- 每页的记录数
@RowCount int = 0 out, -- 总的记录数
@PageCount int = 0 out -- 总的页数
)
AS
IF @PageSize <= 0
BEGIN
RAISERROR('参数 PageSize 必须大于零。', 16, 1);
RETURN
END
DECLARE @p1 int
DECLARE @RowIndex int
SET @CurrentPageIndex = @CurrentPageIndex + 1
EXEC sp_cursoropen
@p1 output,
@SelectCommandText,
@scrollopt = 1,
@ccopt = 1,
@RowCount = @RowCount output;
SET @PageCount = ceiling(1.0 * @RowCount / @PageSize);
SET @RowIndex = (@CurrentPageIndex - 1) * @PageSize + 1
EXEC sp_cursorfetch
@p1,
16,
@RowIndex,
@PageSize;
EXEC sp_cursorclose
@p1
调用方法:
DECLARE @return_value int,
@RowCount int,
@PageCount int
EXEC @return_value = [dbo].[SplitPage]
@SelectCommandText = N'SELECT * FROM Log',
@CurrentPageIndex = 0,
@PageSize = 4,
@RowCount = @RowCount OUTPUT,
@PageCount = @PageCount OUTPUT
SELECT @RowCount as N'@RowCount',
@PageCount as N'@PageCount'
SELECT 'Return Value' = @return_value
GO
@RowCount int,
@PageCount int
EXEC @return_value = [dbo].[SplitPage]
@SelectCommandText = N'SELECT * FROM Log',
@CurrentPageIndex = 0,
@PageSize = 4,
@RowCount = @RowCount OUTPUT,
@PageCount = @PageCount OUTPUT
SELECT @RowCount as N'@RowCount',
@PageCount as N'@PageCount'
SELECT 'Return Value' = @return_value
GO
- SQL Server通用分页存储过程:利用SQL Server未公开的存储过程实现
- SQL Server通用分页存储过程:利用SQL Server未公开的存储过程实现
- SQL Server通用分页存储过程:利用SQL Server未公开的存储过程实现
- 利用SQL未公开的存储过程实现分页
- 利用SQL未公开的存储过程实现分页
- Sql Server通用的分页存储过程
- SQL Server未公开的两个存储过程
- SQL Server未公开的两个存储过程
- SQL Server里一些未公开的扩展存储过程
- SQL Server里一些未公开的扩展存储过程
- SQL Server中部分未公开的存储过程
- SQL Server中部分未公开的存储过程
- SQL Server 2000 未公开的存储过程
- 通用分页存储过程sql-server
- 邹建SQL Server通用分页存储过程
- 邹建SQL Server通用分页存储过程
- 通用分页存储过程(SQL SERVER)
- SQL Server通用分页存储过程
- 学习Linux的七点忠告
- Test
- String.getBytes()的问题
- 精彩的近乎完美的分页存储过程
- delphi杂记
- SQL Server通用分页存储过程:利用SQL Server未公开的存储过程实现
- Java如何打开一个文件夹并选中指定文件
- ASP.NET中的一些字符串操作
- Swing中弹出对话框的几种方式
- 一个asp日历
- 修改收藏夹,我的文档等目录默认位置
- 用Visual C#实现局域网通讯
- ORACLE 10G在RedHat AS4下的安装与卸载
- 创建未绑定的 Windows 窗体 DataGridView 控件