mysql教程

超轻量级php框架startmvc

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

更新时间:2020-04-23 08:30:01 作者:startmvc
ALTERPROCEDURE[a0919194122].[dnt_getappinvitelist]@uidint,@pageindexint,@pagesizeintASDECLARE@startRowint,@endRowintSET@
 
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
mssql 分页