zoukankan      html  css  js  c++  java
  • SQL SERVER 分页查询存储过程

    /****** Object: StoredProcedure [dbo].[usp_selectbypage] Script Date: 01/14/2020 07:51:42 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[usp_selectbypage]
    @tablename varchar(10),
    @columnname varchar(10),
    @page varchar(5), ---页数
    @pagecount varchar(5), --每页行数
    @recordcount int output,--总的记录的条数
    @pageamount int output --总页数
    as
    begin
    declare @strsql nvarchar(255)

    set @strsql = 'select * from (
    select ROW_NUMBER() over (order by ' + @columnname + ' desc) as rowid,* from ' + @tablename + ') t
    where t.rowid >=(('+@page+'-1)*'+@pagecount+'+1) and t.rowid <= ('+@page+'*'+@pagecount+')'

    exec (@strsql) -----不是有效的标识符 sql,exec执行时必须加()

    set @strsql = 'select @count=count(*) from ' + @tablename

    exec sp_executesql @strsql,N'@count int output',@recordcount output

    select @pageamount = CEILING(@recordcount*1.0/@pagecount)

    end

  • 相关阅读:
    三角函数
    第十七次作业
    第十六次作业
    第15次作业
    第13次java作业
    第十二次java作业
    第十一次java作业
    第十次java作业
    第九次java
    第八次java作业
  • 原文地址:https://www.cnblogs.com/jiangyuhu/p/12190232.html
Copyright © 2011-2022 走看看