开发者

Variation on Select top n

开发者 https://www.devze.com 2023-01-04 16:07 出处:网络
Is is possible to do a variation of select top n rows to select top n rows starting at a row other than 0.

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 开发者_JAVA技巧Server 2008


Here's an article which demonstrates such queries using the ROW_NUMBER function.


;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 !

0

精彩评论

暂无评论...
验证码 换一张
取 消