zoukankan      html  css  js  c++  java
  • 一段实现分页的存储过程


    Declare @PageSize int
    set @PageSize=8
    Declare @PageIndex int
    set @PageIndex=1
    --定义输出的参数
    Declare @RecoundCount int
    Declare @DateEof Bit  --output,--返回数据,是否溢出
    Declare @PageCount int  --output--返回数据:总页数

    Declare @TempResult varchar(1000)
    Declare @OrderCommand varchar(1000)
    Set @TempResult = 'Select * From dbo.Info_ProductInfo where Display=1 And Audting=0'


    Declare @GetRCountSumStr nvarchar(1500)
    Set @GetRCountSumStr = 'Select  @RecoundCount = Count(*) From (' + @TempResult + ') as t'
    Exec sp_executesql @GetRCountSumStr,N'@RecoundCount int output',@RecoundCount output

      
      
         
    Declare @ResultMod int
         
    Set @ResultMod = @RecoundCount % @PageSize
         
    If @ResultMod = 0
            
    Set @PageCount = @RecoundCount / @PageSize
          
    Else
            
    Set @PageCount = (@RecoundCount / @PageSize+ 1
         
    Set @DateEof = 0
         
    If @PageIndex < 1
            
    Set @PageIndex = 1

         
    if @PageIndex > @PageCount
            
    Set @PageIndex = @PageCount

         
    Declare @GetProductAuditingList varchar(3000)
         
    Declare @indextable table(id int identity(1,1),PId int)
         
         
    --'Insert Into @indextable(PId)' + @TempResult
         

         
    Set @GetProductAuditingList =('
         Declare @indextable table(id int identity(1,1),SysId int)
         Insert Into @indextable(SysId) Select SysId From (
    ' + @TempResult + ') as t 
         Select P.*,u.UserName,C.CCnName,T.Id From @indextable as T,dbo.Info_UserInfo As u,Info_CompanyInfo as C,dbo.Info_ProductInfo as p Where Id > 
    ' + cast((@PageSize * @PageIndex- @PageSize as varchar(10)) + ' And Id <= ' + cast((@PageSize * @PageIndexas varchar(10)) + 
         
    'And P.SysId = T.SysId And p.UserId=u.SysId and P.CompanyId=C.SysID Order By T.Id')



         
    Exec(@GetProductAuditingList)
      

  • 相关阅读:
    php smarty使用..
    深圳面试!
    jQuery 源码分析..
    jQuery 使用技巧!!!
    TOMCAT 访问过程...
    准备使用Delphi调用WCF
    Delphi 中Format的字符串格式化使用说明(转载http://hi.baidu.com/test__123/blog/item/e3bba1599d717a2d2834f092.html)
    电脑启动程序自动启动
    判断输入字符串是否等效Int32位数字的两种方法
    vs2005 快捷键
  • 原文地址:https://www.cnblogs.com/ddr888/p/683599.html
Copyright © 2011-2022 走看看