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注册。

  • 相关阅读:
    Iview多行表单增删、表单校验
    Linux常用命令+Git命令
    前端架构师图谱
    第八章学习心得
    第七章学习心得
    第6章学习心得
    第5章学习总结
    第四章心得体会
    第三章学习心得
    第二章学习心得
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319496.html
Copyright © 2011-2022 走看看