Is is possible to do a variation of select top n rows to select top n rows starting at a row other than 0. My (mobile) app has limited resources and no server side caching available. The maximum rows returned is 100. I get the first 100 by select top 100. I would then like the user to be then able to request rows 101-200 and so on. The database data is static and the the re-query time negligible. Platform SQL Server 2008
+2
A:
Here's an article which demonstrates such queries using the ROW_NUMBER function.
Darin Dimitrov
2010-06-26 08:26:08
+1
A:
;With CTETable AS
(
SELECT ROW_NUMBER() OVER (ORDER BY Column_Name DESC) AS ROW_NUM, * FROM TABLENAME WHERE <CONDITION>
)
SELECT Column_List FROM CTETable WHERE ROWN_NUM BETWEEN <StartNum> AND <EndNum>
Use your [startNum] and [EndNum] to be any series you want maybe 123 - 147 ! This will work well !
Baaju
2010-06-26 08:28:05