USE [QHWCloud] GO /****** Object: StoredProcedure [dbo].[pr_paginationbyMoney] Script Date: 09/06/2017 15:39:37 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ------------------------------------ --describe:实现简单分页 --time: 2014-5-3 16:03:56 --parm: @where 条件筛选 -- @pageindex 第几页 -- @pagesize 每页多少条数据 -- @type 操作类型(0:获取总条数;1:获取分页数据集;2:获取总条数和分页数据集) -- @sum输出参数 总条数 ------------------------------------ ALTER proc [dbo].[pr_paginationbyMoney] @where nvarchar(4000), --查询条件 @pageindex int, @pagesize int, @type int, @srcSum int, @sum int output as set @sum=0 declare @sql nvarchar(4000),@count int declare @whereStr nvarchar(2000)='' set @count=@srcSum if LEN(@where)>0 begin set @whereStr='where 1=1 '+@where end if(@type=0 or @type=2 or @count<=0)--获取总条数 begin print 1 set @sql='select @aa=count(1) from vw_moneyReciveAll T '+ @whereStr exec sp_executesql @sql,N'@aa int output',@count output end set @sum= @count if @type=0--只查总数直接返回 begin select 1 return end if(@type=1 or @type=2) begin set @sql=' select tt.*, case orderRow when 1 then pay_money else 0 end as paymoney, case orderRow when 1 then mi_fee else 0 end as fee from (select ROW_NUMBER()OVER( PARTITION BY mi_id order by mi_id desc ) as orderRow ,ROW_NUMBER()OVER( order by mi_id desc ) as Row,t.pay_name,t.pay_money,t.ci_name,t.mi_receivermoney,t.mi_category,t.pay_image,t.mi_state,t.de_names,t.mi_realname,t.mi_createtime,t.mi_endtime,t.re_datetime,t.mr_pay_modename,t.mr_packname,t.mi_fee,t.ci_province_name,t.miid as mi_id,t.pay_modename,t.pay_time from vw_moneyReciveAll as t '+@whereStr +' ) as tt where tt.Row>'+CAST( (@pageindex-1)*@pagesize as varchar)+' and tt.Row<='+CAST(@pageindex*@pagesize as varchar) exec sp_executesql @sql end