ROW_NUMBER分页
var query = string.Format("SELECT {0} FROM (SELECT ROW_NUMBER() OVER (ORDER BY {3}) AS RowNum, {0} FROM {4} where {5}) AS Paged WHERE RowNum >= {1} AND RowNum < {2} ORDER BY RowNum", columns, (pageSize-1)*pageIndex,pageSize*pageIndex, orderBy, tableName, where);
SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY InsertDate) AS RowNum, *
FROM Posts
WHERE InsertDate >= '1900-01-01'
) AS result
WHERE RowNum >= 1 // *your pagination parameters
AND RowNum < 20 //*
ORDER BY RowNum
================================
sqlserver 2012
SELECT * FROM [Posts]
ORDER BY [InsertDate]
OFFSET 20 ROWS
FETCH NEXT 5 ROWS ONLY