zoukankan      html  css  js  c++  java
  • 一个简单的分页存储过程

    create proc Pager
    @PageIndex int,
    @PageSize int,
    @PageCount int out,
    @RecordCount int out
    as
    select @RecordCount= count(*) from film_type
    set @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
    declare @topCount int
    SET @topCount = @RecordCount - @PageSize * @PageIndex
    DECLARE @SQLSTR NVARCHAR(1000)
    if @PageIndex=0 or @RecordCount <=0
    begin
        set @SQLSTR=N'select top '+str(@PageSize) +' film_id,film_name from film_type order by film_id desc'
    end
    else
    begin
       if @PageIndex=@PageCount-1
       begin
          set @SQLSTR=N'select * from (select top '+str(@topCount)+' film_id,film_name from film_type order by film_id asc)T order by film_id desc'
       end
       else
       begin
         set @SQLSTR=N'select top '+str(@PageSize)+' * from (select top '+str(@topCount)+' film_id,film_name from film_type order by film_id asc)T order by film_id desc '
       end
    end
    print @SQLSTR
    EXEC (@SQLSTR)

    drop proc Pager

    declare @pageCount int
    declare @recordCount int
    exec Pager 0,5,@pageCount out,@recordCount out

    本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

  • 相关阅读:
    BZOJ 1036 [ZJOI2008]树的统计Count(动态树)
    HDU 4010 Query on The Trees(动态树)
    Bootstrap框架
    【价格谈判】——在生意场合胜出的50个谈判绝招
    导出
    邓_ Php·魔术方法
    邓_tp_笔记
    UI 网页三原色
    邓_ 表单验证
    邓_ ThinkPhp框架
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319496.html
Copyright © 2011-2022 走看看