CREATE proc pt_GetRechargeLog
(
@pageIndex int,
@pageSize int
)
as
declare @sql nvarchar(1024)
select @pageIndex = (@pageIndex-1) * @pageSize
select @sql = N'select top '+ str(@pageSize) +' * from [RechargeLog] where [ReChargeID] not in (select top ' + str(@pageIndex) + ' [ReChargeID] from [RechargeLog] order by [ReChargeTime] desc) order by [ReChargeTime] desc'
exec sp_executesql @sql
---不好意思,上面的是有点错误,用这个吧。
create table tb(mid int)
insert tb
select 2
union all select 2
union all select 4
union all select 4
union all select 4
union all select 5
union all select 6
union all select 7
go
create proc p @page int,@pagecount int
as
declare @str varchar(1000)
set @page=@page-1
set @str='select * from tb where mid in (select top '+rtrim(@pagecount)+' mid from tb where mid not in (select top '+rtrim(@page*@pagecount)+ 'mid from tb group by mid) group by mid)'
exec(@str)
create table tb(mid int)
insert tb
select 2
union all select 2
union all select 4
union all select 4
union all select 4
union all select 5
union all select 6
union all select 7
go
create proc p @page int,@pagecount int
as
declare @str varchar(1000)
set @page=@page-1
set @str='select * from tb where mid in (select top 2 mid from tb where mid not in (select top '+rtrim(@page*@pagecount)+ 'mid from tb group by mid) group by mid)'
exec(@str)