Hi Guys,The COUNT(*) OVER was taking longer to run. I did a test, I created a table with an INT and an NVARCHAR columns. I inserted 1 million rows and run the following query:--Query 1declare @START_ROW_INDEX int, @MAX_ROWS int, @TR intselect @START_ROW_INDEX = 0, @MAX_ROWS = 50;WITH PQRY AS ( select ROW_NUMBER () OVER (ORDER BY personid) as RowNum , count(*) over() TotalRows , [name]from person) SELECT * FROM PQRY WHERE RowNum BETWEEN @START_ROW_INDEX AND (@START_ROW_INDEX + @MAX_ROWS) - 1GO--Query 2declare @START_ROW_INDEX int, @MAX_ROWS int, @TR intselect @START_ROW_INDEX = 0, @MAX_ROWS = 50;select @TR=count(*) from person;WITH PQRY AS ( select ROW_NUMBER () OVER (ORDER BY personid) as RowNum, [name]from person) SELECT * FROM PQRY WHERE RowNum BETWEEN @START_ROW_INDEX AND (@START_ROW_INDEX + @MAX_ROWS) - 1GO
Query 1 runs an average of 3 seconds and Query 2 runs in less than a second.I just thought I share that.