Fetching Records using Keyset-driven Cursor in SQL Server 2008
In this article I describe how to fetch first, next, last, or any specific row with the help of keyset-driven cursor.
Introduction
In my previous article I describe about keyset-driven cursor. Now in this article I describe how to fetch first, next, prior, last, or any relative row with the help of keyset-driven cursor.
Fetching data using keyset-driven Cursor:
Opening of keyset-driven Cursor:
We open a keyset-driven cursor as in the in following:
Fetching the first data using keyset-driven Cursor:
fetch First from key_cursor
|
Output:

Fetching next data using keyset-driven Cursor:
fetch next from key_cursor
|
Output:

Fetching previous data using keyset-driven Cursor:
fetch prior from key_cursor
|
Output:

Fetching next 2nd data using keyset-driven Cursor:
fetch relative 2 from key_cursor
|
Output:

Fetching last data using keyset-driven Cursor:
fetch last from key_cursor
|
Output:

Closing and Deallocating the keyset-driven Cursor:
We close and deallocate Dynamic Cursor as in the following:
close key_cursor
deallocate key_cursor
|