码迷,mamicode.com
首页 > 数据库 > 详细

SQL分页小Demo

时间:2016-05-21 15:55:28      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/wu-peng/p/5514824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!