CodeCopy

July 15, 2010

SQL paging

Filed under: SQL — sterndorff @ 08:38

How to fetch from a table row number 10 to 20:

SELECT [t1].*
FROM (
   SELECT ROW_NUMBER() OVER (
   ORDER BY [t0].<primarykey>) AS [ROW_NUMBER],  [t0].*
   FROM [dbo].[<tablename>] AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN <fromrow> AND <torow>
ORDER BY [t1].[ROW_NUMBER]

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.