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

Fetching next data using Static Cursor:
fetch next from static_cursor
|
Output:

Fetching last data using Static Cursor:
fetch last from static_cursor
|
Output:

Fetching 4th data using Static Cursor:
This fetches the specific data giving absolute position:
fetch absolute 4 from static_cursor
|
Output:

Fetching next 2nd data using Static Cursor:
fetch relative 2 from static_cursor
|
Output:

Closing the Static Cursor:
We close Static Cursor as in the following
Dealloting Static Cursor:
We deallocate Static Cursor as following