示例代码:
DECLARE @endRow INT;
DECLARE @filed NVARCHAR(128);
DECLARE @sort NVARCHAR(10);
DECLARE @SQL NVARCHAR(300);
-- Insert statements for procedure here
SET @pageIndex = 1;
SET @pageSize = 2;
SET @startRow = (@pageIndex - 1) * @pageSize + 1;
SET @endRow = @startRow + @pageSize - 1;
SET @filed = N'([leagueBattleWin] + [leagueBattleLost])';
SET @sort = N'DESC';
SET @SQL = 'SELECT * FROM
(SELECT *,
ROW_NUMBER() OVER (ORDER BY ' + @filed + ' ' + @sort + ') AS RowNumber FROM [dbo.spt_mointor]) T
WHERE T.RowNumber BETWEEN ' + STR(@startRow) + ' AND '+ STR(@endRow)
EXEC (@SQL)