欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MSSQL根据ID进行分页实现方法

程序员文章站 2024-02-17 14:25:40
复制代码 代码如下: 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