分页的存储过程

发布时间:2022-04-18 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了分页的存储过程脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
复制代码 代码如下:

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



在要用的时候在那个存储过程里调用
复制代码 代码如下:
@H_304_44@
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


脚本宝典总结

以上是脚本宝典为你收集整理的分页的存储过程全部内容,希望文章能够帮你解决分页的存储过程所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: