select top 10 *,(select count(1) from table) as cnt from table where id not in ..
2.技术要点
在SQL Server中要实现SQL分页,需要使用子查询来获取上一页的数据进行对比,进而获取最新的数据。使用子查询获取分页数据的语法格式如下:
"SELECT TOP [pageSize] * FROM [table] WHERE id NOT IN(
SELECT TOP [preNum] id FROM [table] ORDER BY ID DESC) ORDER BY ID DESC";
3.创建存储过程
CREATE
PROCEDURE
p1(
@PageCount
INT
,
--页码
@PageSize
INT
,
--页显示记录数
@RowCount
INT
OUTPUT
)
AS
SELECT
@RowCount=
COUNT
(1)
FROM
sys.tables
SELECT
a.
name
FROM
(
SELECT
name
,ROW_NUMBER()OVER(
ORDER
BY
object_id)
AS
Row
FROM
sys.tables)
AS
a
WHERE
Row
BETWEEN
(@PageCount-1)*@PageSize+1
AND
@PageCount*@PageSize
GO
DECLARE
@RowCount
INT
EXEC
p1 @PageCount=1,@PageSize=30,@RowCount=@RowCount
OUTPUT
SELECT
@RowCount