I have the following query where I would like to return two result sets. One being the results as a table and the second just returning the number of potential results, or MaxResults.
The last line errors with Invalid object name ResultsTemp. It does not work until I comment out the second last line. It appears I can only use the ResultsTemp once.
DECLARE @StartRow int;
DECLARE @MaxRows int;
set @StartRow = 0;
set @MaxRows = 5;
WITH ResultsTemp AS
(
SELECT ROW_NUMBER() OVER (ORDER BY FTS.RANK DESC) AS RowId,
Id, Name FROM tNews
INNER JOIN CONTAINSTABLE(tNews, *, 'FORMSOF(INFLECTIONAL, hello)')
AS FTS ON tNews.Id = FTS.[KEY]
)
SELECT Id, Name, RowId FROM ResultsTemp
Group By Id, Name, RowId
Having RowId between @StartRow and (@StartRow + @MaxRows);
select COUNT(*) from ResultsTemp;
thank you
1 Answer