您的位置:首页 > 数据库

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

2012-11-20 00:00 513 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: