当前位置: 首页 > 图文教程 > 数据库 > MSSQL > 分页的存储过程

MSSQL
使用SQL Server索引视图来提高性能
步骤指南:移植SQL 2000 DTS到SSIS
怎样使你的SQL运行得更加灵活和高效
优化SQL Server数据库服务器内存配置
SQL SERVER优化建议
请注意那些容易被忽略的SQL注入技巧
SQL Server 2005密码安全追踪与存储
sql2000下 分页存储过程
SQL Server数据库安全管理经验谈
测试SQL Server的业务规则链接方法
SQL Server的有效安装
SQL Server灾难恢复:重创历史性数据
SQL Server2005发布元年 微软正身企业级应用
MS SQL "1813"错误产生的原因及解决
收藏几段SQL Server语句和存储过程
SQL Server 2005中的备份和恢复增强
如何用SQL Server查询累计值
浅析如何掌握SQL Server的锁机制
步骤指南:测试MSSQL有没有特洛伊木马
手工卸载SQL Server 2000数据库

MSSQL 中的 分页的存储过程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 54 ::
收藏到网摘: n/a

复制代码 代码如下:

Create procedure sp_pageQuery
@sqlstr nvarchar(4000),
@page_index int,
@page_size int ,
@rec_count int out --
as
set nocount on
declare @cursor_id int
declare @rowcount int
exec sp_cursoropen @cursor_id output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
set @rec_count=@rowcount
set @page_index=(@page_index-1)*@page_size+1
IF @rec_count>0
BEGIN
exec sp_cursorfetch @cursor_id,16,@page_index,@page_size
END
ELSE
BEGIN
Select 'test'='null' Where 1=2
END
exec sp_cursorclose @cursor_id
set nocount off
GO


在要用的时候在那个存储过程里调用
复制代码 代码如下:

Create PROCEDURE [dev].[P_Mobile_Comment_Page]
@course_ware_id int,
@recCountPerPage int=1,
@pageIndex int =1,
@recordCount int=0 out
AS
DECLARE @sql nvarchar(4000)
SET @sql="
Select seg_id,course_ware_id,subject,cust_name,content,create_date
FROM T_COURSEWARE_COMMENT
Where course_ware_id="+cast(@course_ware_id as varchar(10))+"
ORDER BY seg_id"
EXEC sp_Pagequery @sql,@pageIndex,@recCountPerPage,@recordCount out
GO