Showing posts with label sql server paging and sorting. Show all posts
Showing posts with label sql server paging and sorting. Show all posts

Monday, December 08, 2008

SQL Server Paging and Sorting

SELECT * FROM (
SELECT TOP x * FROM (
SELECT TOP y fields
FROM table
WHERE conditions
ORDER BY table.field ASC) as foo
ORDER by field DESC) as bar
ORDER by field ASC

x is the number of rows you want returned and y is x+offset