SELECT * FROM (
SELECT
ROW_NUMBER()
OVER(ORDER BY ca.PraiseNum desc) as RowID
,ca.[ArticleId]
,ca.[ActivityId]
,ca.[Title]
,ca.[UserID]
,ca.[CreateTime]
,ca.[IsDeleted]
,ca.[PraiseNum]
,tu.UserName
,ca.[IsSendCoupon]
FROM [dbo].[CarArticle] ca WITH(NOLOCK)
INNER JOIN dbo.View_TradeUser tu WITH(NOLOCK) ON
tu.UserID=ca.UserID
WHERE ca.ISDeleted = 0 AND ca.Status = 1 AND
Marrow = 3 AND ca.[ActivityId] = @ActivityID AND tu.Islocal =0
)
Temp WHERE RowID Between @StartRow AND @EndRow
SELECT
@RecordCount=COUNT(*) FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY ca.PraiseNum desc) as RowID
,ca.[ArticleId]
,ca.[ActivityId]
,ca.[Title]
,ca.[UserID]
,ca.[CreateTime]
,ca.[IsDeleted]
,ca.[PraiseNum]
,tu.UserName
,ca.[IsSendCoupon]
FROM [dbo].[CarArticle] ca WITH(NOLOCK)
INNER JOIN dbo.View_TradeUser tu WITH(NOLOCK) ON
tu.UserID=ca.UserID
WHERE ca.ISDeleted = 0 AND ca.Status = 1 AND
Marrow = 3 AND ca.[ActivityId] = @ActivityID AND tu.Islocal =0
)TEMP
原文地址:http://www.cnblogs.com/q101301/p/3718377.html