Fetching Records using Dynamic Cursor in SQL Server 2008
In this article I describe how to fetch first, next, last, or any specific row with the help of dynamic cursor.
Introduction
In my previous article I describe about dynamic cursor. Now in this article I describe how to fetch first, next, prior, last, or any relative row with the help of dynamic cursor.
Fetching data using Dynamic Cursor:
Opening of Dynamic Cursor:
We open a dynamic cursor as in the in following:
Fetching the first data using Dynamic Cursor:
fetch first from dynamic_cursor
|
Output:
Fetching next data using Dynamic Cursor:
fetch next from dynamic_cursor
|
Output:
Fetching previous data using Dynamic Cursor:
fetch prior from dynamic_cursor
|
Output:
Fetching next 2nd data using Static Cursor:
fetch relative 2 from dynamic_cursor
|
Output:
Fetching last data using Dynamic Cursor:
fetch last from dynamic_cursor
|
Output:
Closing and Deallocating the Dynamic Cursor:
We close and deallocate Dynamic Cursor as in the following:
close dynamic_cursor
deallocate static_cursor
|