一个利用CTE递归在存储过程中实现真分页的代码示例

数据库 SQL Server
本文主要给出了一个利用CTE递归在存储过程中实现真分页的代码示例,供初学者参考,希望能够对您有所帮助。

利用CTE递归存储过程中实现真分页的技术还是比较简单的,本文我们给出了一个利用CTE递归在存储过程中实现真分页的代码示例,对于初学者来说可以套用下面的代码,代码示例如下:

  1. SET ANSI_NULLS ON    
  2.  
  3. GO    
  4.  
  5. SET QUOTED_IDENTIFIER ON    
  6.  
  7. GO    
  8.  
  9. ALTER proc [dbo].[BIReport_GetAllReport_Page]    
  10.  
  11. @currentpage int,--当前页码     
  12.  
  13. @pagesize int  --每页显示的条数     
  14.  
  15. as      
  16.  
  17. declare @beginindex   int    
  18.  
  19. declare @endindex  int    
  20.  
  21. begin    
  22.  
  23. select @beginindex=(@currentpage-1)*@pagesize    
  24.  
  25. select @endindex=@beginindex+@pagesize    
  26.  
  27. end     
  28.  
  29. begin    
  30.  
  31. With X as   --CTE递归          
  32.  
  33. (        
  34.  
  35. Select *, row_number() over(order by ReportId) as rowNum    
  36.  
  37. From BIReport    
  38.  
  39. )    
  40.  
  41. select * from X     
  42.  
  43. where rowNum between @beginindex+1 and @endindex    
  44.  
  45. end 

 

以上就是利用CTE递归在存储过程中实现真分页的代码,希望通过阅读上面的代码,能够带给您一些收获吧。

【编辑推荐】

  1. 如何Master Data Service调用API创建Model
  2. SQL查询优化实例:银行校园卡缴费的性能优化
  3. SQL Server 2008数据库Analysis Services基础知识介绍
  4. SQL Server CPU性能排查及优化相关SQL语句使用简介
  5. SQL无人值守安装的IACCEPTSQLSERVERLICENSETERMS参数
责任编辑:赵鹏 来源: CSDN博客
相关推荐

2010-05-05 17:19:32

Oracle存储过程

2010-05-05 14:55:15

Oracle存储过程

2010-04-29 17:31:56

Oracle存储过程

2010-04-12 09:26:52

Oracle查询分页

2011-05-17 15:13:59

oracle分页存储

2011-08-16 16:59:58

PLSQL分页存储过程Java

2012-04-23 15:10:18

ASP.NET

2010-04-16 10:42:10

Oracle存储过程

2011-08-18 17:32:40

Oracle存储过程利用游标返回结果集

2010-11-29 09:12:46

sybase分页存储过

2011-03-28 09:56:03

存储增删操作

2010-10-11 09:05:40

SQL Server

2010-04-30 08:47:22

Oracle分页存储

2017-12-19 07:09:22

数据中心合并IT

2011-08-11 14:35:47

SQL Server插入更新

2009-07-23 14:10:38

Hibernate J

2011-04-11 17:28:50

oracle存储select语句

2010-03-30 13:19:57

Oracle存储

2010-06-11 14:41:20

MySQL分页查询

2010-05-31 16:57:09

点赞
收藏

51CTO技术栈公众号