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.
  • 2851

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:

open dynamic_cursor

Fetching the first data using Dynamic Cursor:

fetch first from dynamic_cursor

Output:

dynamic-cursor-in-sql-server-first1.jpg

Fetching next data using Dynamic Cursor:

fetch next from dynamic_cursor

Output:

dynamic-cursor-in-sql-serever-nest2.jpg

Fetching previous data using Dynamic Cursor:

fetch prior from dynamic_cursor

Output:

dynamic-cursor-in-sql-serever-priveos3.jpg

Fetching next 2nd data using Static Cursor:

fetch relative 2 from dynamic_cursor

Output:

dynamic-cursor-in-sql-serever-relative4.jpg

Fetching last data using Dynamic Cursor:

 fetch last from dynamic_cursor

Output:

dynamic-cursor-in-sql-serever-last5.jpg

Closing and Deallocating the Dynamic Cursor:

We close and deallocate Dynamic Cursor as in the following:

close dynamic_cursor
deallocate static_cursor

© 2020 DotNetHeaven. All rights reserved.