is this possible using T-SQL?
A:
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/
JoshVarga
2010-09-02 16:50:10
thats complicated :X
Alan
2010-09-02 16:52:48
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
2010-09-02 17:12:39
+1
A:
If you're using SQL Server 2005 or greater, check out the ROW_NUMBER function: http://msdn.microsoft.com/en-us/library/ms186734.aspx
joelt
2010-09-02 16:59:42
A:
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;
Alan
2010-09-02 18:22:16