Hello everyone,
I am using SQL Server 2008 Enterprise on Windows Server 2008 Enterprise. I am using the following code to return a part of data for a query to implement paging (i.e. page up/down to show a part of result at each page, like Google search result paging) on my web application (I use pageCount as number of results showed on each page, and startPos as the start number of result). For example, pageCount 10 means show 10 results for each page, startPos = 0 means the first page, startPos = 1 means the 2nd page, etc.
My question is how to get the total number of results efficiently in my scenario? My major concern is how to implement paging (i.e. touch only a part of result) and at the same time retrieve the total number of results?
SELECT *
FROM (SELECT
t.foo, t.goo, ROW_NUMBER() OVER (order by t.zoo DESC ) AS rowNum
FROM
dbo.mycorp t
WHERE
(t.foo LIKE '%'+@search+'%'
or t.foo LIKE '%'+@search+'%'
)
) tt
WHERE tt.rowNum between @startPos and @pageCount + @startPos-1
thanks in advance, George