|
----“ABSOLUTE” n returns the nth row From the Top, “ABSOLUTE” -n returns the nth row From the Bottom.
DECLARE myCursor CURSOR
LOCAL
KEYSET
FOR SELECT Name FROM EMP
DECLARE @nTop CHAR(10)
DECLARE @nBtm CHAR(10)
OPEN myCursor
---- Retrieve the 3rd row from the Top
FETCH ABSOLUTE 3 FROM myCursor INTO @nTop
---- Retrieve the 5th row from the Bottom
FETCH ABSOLUTE -5 FROM myCursor INTO @nBtm
SELECT @nTop as 'I am 3rd Row from Top',
@nBtm as 'I am 5th Row from Bottom'
CLOSE myCursor
DEALLOCATE myCursor
|