|
DECLARE myCursor CURSOR
LOCAL
KEYSET
FOR SELECT Name FROM EMP
DECLARE @fRow CHAR(10)
DECLARE @nRow CHAR(10)
DECLARE @lRow CHAR(10)
DECLARE @pRow CHAR(10)
OPEN myCursor
---- Retrieve the First row into a variable
FETCH FIRST FROM myCursor INTO @fRow
---- Retrieve the Next row
FETCH NEXT FROM myCursor INTO @nRow
---- Retrieve the Last row into a variable
FETCH LAST FROM myCursor INTO @lRow
---- Retrieve the Previous row
FETCH PRIOR FROM myCursor INTO @pRow
SELECT @fRow as 'I am From First Row',
@nRow as 'I am From the Next Row',
@lRow as 'I am From Last Row',
@pRow as 'I am From the Previous row'
CLOSE myCursor
DEALLOCATE myCursor
|