SQL Snippet for Paging

April 18, 2007 at 11:49 am (SQL)

Microsoft SQL 2005 finally introduced better support for doing paging at the database level. I’m a little disappointed that MS is not pushing to use this as the default method for paging, instead of relying on ASP.NET controls.

1 USE AdventureWorks 2 GO 3 4 SELECT * FROM ( 5 SELECT 6 ROW_NUMBER() OVER (ORDER BY SellStartDate ASC) AS rownumber,* 7 FROM Production.Product 8 ) AS Product 9 WHERE rownumber between @FromRow AND @ToRow
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: