给定以下 SQL:
;WITH Results AS
(
SELECT ItemListID, Title,
ROW_NUMBER() OVER(ORDER BY ItemListID DESC) as intRow,
COUNT(ItemListID) OVER() AS ActualNumberOfResults
FROM ItemData
WHERE FREETEXT(Title, @FTSSearchTerm)
AND WebsiteID = @WebsiteID
AND ContentTypeID = @ContentTypeID
AND GeoID2 = @GeoID
)
SELECT * FROM Results
WHERE intRow BETWEEN @intStartRow AND @intEndRow
ORDER BY ItemListID DESC
SELECT @NumberOfResultsReturned = @@ROWCOUNT
我想将一个参数 @ActualNumberOfResults 设置为从 CTE 返回的 TOP(1) ActualNumberOfResults 的值。
在 CTE 之后,我使用了以下内容,但似乎重复:
SELECT @ActualNumberOfResults = COUNT(*)
FROM ItemData
WHERE CONTAINS(Title, @FTSSearchTerm )
AND WebsiteID=@WebsiteID
我怎样才能做到这一点?