|
----“RELATIVE” n returns a Row “n” rows From the current Row. “RELATIVE” -n returns a Row “n” rows Before the current Row.
DECLARE myCursor CURSOR
LOCAL
KEYSET
FOR SELECT Name FROM EMP
DECLARE @Name1 char(10)
DECLARE @Name2 char(10)
DECLARE @Name3 char(10)
DECLARE @Name4 char(10)
OPEN myCursor
---- Retrieve the 2nd row from the Top
FETCH ABSOLUTE 2 FROM myCursor INTO @Name1
---- Retrieve the 4th Row from the 2nd Top Row
FETCH RELATIVE 4 FROM myCursor INTO @Name2
---- Retrieve the 3rd row from the Bottom
FETCH ABSOLUTE -3 FROM myCursor INTO @Name3
---- Retrieve the 6th Row from the 3rd Bottom Row
FETCH RELATIVE -6 FROM myCursor INTO @Name4
SELECT @Name1 as 'I am 2nd Row from Top',
@Name2 as 'I am 4th Row From the 2nd Top Row',
@Name3 as 'I am 3rd Row from Bottom',
@Name4 as 'I am 6th Row from the 3rd Bottom Row'
CLOSE myCursor
DEALLOCATE myCursor
|