萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mssql數據庫 >> MSSQL根據ID進行分頁實現方法

MSSQL根據ID進行分頁實現方法

代碼如下:

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

copyright © 萬盛學電腦網 all rights reserved