熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> MySQL >> 正文

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

2013-11-23 21:04:18  來源: MySQL 

  代碼如下:

  ALTER PROCEDURE [a][dnt_getappinvitelist]
@uid int
@pageindex int
@pagesize int
AS
DECLARE @startRow int
@endRow int
SET @startRow = (@pageIndex ) * @pagesize
IF @pageindex =
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


From:http://tw.wingwit.com/Article/program/MySQL/201311/29525.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.