zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

2023-03-31 11:09:01 时间

利用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参数