MSSQL根据ID进行分页实现方法
程序员文章站
2023-12-20 22:14:46
复制代码 代码如下: alter procedure [a0919194122].[dnt_getappinvitelist] @uid int, @pageindex i...
复制代码 代码如下:
alter procedure [a0919194122].[dnt_getappinvitelist]
@uid int,
@pageindex int,
@pagesize int
as
declare @startrow int,
@endrow int
set @startrow = (@pageindex - 1) * @pagesize
if @pageindex = 1
begin
exec(
'select top '+@pagesize+' [id],[typename],[appid],[type],[fromuid],[touid],[myml],[datetime],[hash] from [dnt_myinvite] where [touid]='+@uid+' order by [id] desc'
)
end
else
begin
exec('
select
top '+@pagesize+'
[id],[typename],[appid],[type],[fromuid],[touid],[myml],[datetime],[hash]
from [dnt_myinvite]
where [touid]='+@uid+'
and [id] < (select min([id]) from (select top '+@startrow+' [id]
from [dnt_myinvite]
where [touid]='+@uid+'
order by [id] desc
) as t
)
order by [id] desc
')
end
推荐阅读