SQL分页小Demo
Posted 路上
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL分页小Demo相关的知识,希望对你有一定的参考价值。
SELECT
@TotalCount=count(1)
FROM TableA A WITH(NOLOCK)
INNER JOIN TableB B WITH(NOLOCK)
ON A.Id=B.Id
WHERE
A.Name=ISNULL(@name,A.Name)
AND
A.Age=ISNULL(@Age,A.Age)
AND
B.Address=ISNULL(@Address, B.Address)
AND
B.GoodsName like ‘%‘+ISNULL(@GoodsName,‘‘)+‘%‘
SELECT *
FROM
(
SELECT TOP(@EndNumber)
A.Name,
A.Age,
B.Address,
B.GoodsName,
ROW_NUMBER() OVER(ORDER BY A.CreationTime DESC) AS RowNumber
FROM TableA A WITH(NOLOCK)
INNER JOIN TableB B WITH(NOLOCK)
ON A.Id=B.Id
WHERE
A.Name=ISNULL(@name,A.Name)
AND
A.Age=ISNULL(@Age,A.Age)
AND
B.Address=ISNULL(@Address, B.Address)
AND
B.GoodsName like ‘%‘+ISNULL(@GoodsName,‘‘)+‘%‘
) a
where RowNumber>@StarNumber
以上是关于SQL分页小Demo的主要内容,如果未能解决你的问题,请参考以下文章