sql Paging

Select
	Column1,
	Column2
From
	(
		Select
			ROW_NUMBER() OVER (ORDER BY Column1 DESC) AS RowNumber,
			Column1,
			Column2
		From TableName
	) As TableNameWithRowNumbers
Where RowNumber >= 1 AND RowNumber <= 5
--
Select
	Column1,
	Column2
From
	(
		Select
			ROW_NUMBER() OVER (ORDER BY Column1 DESC) AS RowNumber,
			Column1,
			Column2
		From TableName
	) As TableNameWithRowNumbers
Where RowNumber >= 5 AND RowNumber <= 10
Example of paging using ROW_NUMBER.

Updated: Saturday 9th October 2010, 11:42pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.