Description

This demo shows how to replace code that was based on CTEs and ROW_NUMBER() to provide query pagination in earlier versions of SQL Server, to use the new OFFSET and FETCH clauses provided by SQL Server 2012.

The Discussion

Quite often to do pagination effectively, you also need to have the total number of rows that the query would return without implementing the pagination. The way to do this currently with MSSQL is to basically run the same query twice, but with one that doesn't use the WHERE clause to alter your result count.