首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

MSSQL依据ID进行分页

2012-11-25 
MSSQL根据ID进行分页ALTER PROCEDURE [a0919194122].[dnt_getappinvitelist]@uid int,@pageindex int,@pag

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 --www.52mvc.com


热点排行