0

Is it possible to get the values of just rows 10 through 20? If so how?

1
  • Yes, it is possible. ;-)
    – Lucero
    Sep 2, 2010 at 17:01

3 Answers 3

1

If you're using SQL Server 2005 or greater, check out the ROW_NUMBER function: http://msdn.microsoft.com/en-us/library/ms186734.aspx

0
0

One way is to do something like the following...

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.

http://josephlindsay.com/archives/2005/05/27/paging-results-in-ms-sql-server/

1
  • If you post code or XML, please highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it!
    – marc_s
    Sep 2, 2010 at 17:12
0

Hey, by the asnwer of joelt about row_number(). I did it. Its like this:

SELECT allianceId, position, points from (select ROW_NUMBER() over (Order by Points DESC) as position, points, allianceId from Alliance) as somethingx where position >= @alliancePosition - 5 and position <= @alliancePosition + 5;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.