Recently I was asked to write a SQL statement that would return the details of records between two positions. (e.g. all the records from the 11th record to the 20th record). Initially this seemed to be very simple. It was only when I went looking for the statement to do this that I realised it didn't exist (at least not that I'm aware of, I could be wrong and if I am please let me know so I can hang my head in shame!!)
To cut a long story short, I came up with the following statement
SELECT
TOP
[intTo - intFrom + 1]
*
FROM
(
SELECT
*
FROM
some_table
WHERE
some_table.primary_key
NOT
IN
(
SELECT
TOP
[intFrom - 1]
some_table.primary_key
FROM
some_table ))
AS
dummy_table
ORDER
BY
dummy_table.primary_key
In this example, intFrom is the position of first record you want returned, intTo is the position of the last record you want returned. For example, if you want all the records between position 21 and the 30 (i.e. intFrom=21, intTo=30), the statement would be:
SELECT
TOP
10 *
FROM
(
SELECT
*
FROM
some_table
WHERE
some_table.primary_key
NOT
IN
(
SELECT
TOP
20
some_table.primary_key
FROM
some_table ))
AS
dummy_table
ORDER
BY
dummy_table.primary_key
Anyways, I hope this helps someone!