Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Caching and paging a SQL Result Set

By Greg Ryan,

This is an example of how to Cache Query results on the Server side
then page though the results 
!!!This process should be reserved for queries that normally take a long time 
where running the base query for each page results in a unacceptable time lag between pages!!
This is for use with Mobile devices to avoid pulling large or complex data sets
across the connection and trying to cache them on the device then page 
through them
This Caches the complex query results the first pass, avoiding running the complex query
each time you page. Once cached, you can page through the simple cached table to return 
the results to the client one page at a time, avoiding the client side caching.
The line count and page count of your result set are returned with each query so you can keep track
of your position in the dataset
Final pass, you can (and should) destroy the table after use.
By using TempDB you avoid the orphaned table problem, if the client disconnects unexpectedly, 
as TempDB is cleaned up each time SQL is restarted.

Total article views: 1372 | Views in the last 30 days: 55
 
Related Articles
FORUM

Avoid repeatation

Avoid repeatation in query result

FORUM

Avoiding Dynamic Queries

Avoiding Dynamic Queries

FORUM

Custom Pagination with Complex Queries

Is there a better approach for complex queries?

SCRIPT

Paginating a SQL query result set

How to Paginate a query result set to keep from pulling the whole result set to the client side

FORUM

complex query

complex query

Tags
cashing    
paging    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones