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

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:

open static_cursor

Fetching the first data using Static Cursor:

fetch first from static_cursor

Output:

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

Fetching next data using Static Cursor:

fetch next from static_cursor

Output:

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

Fetching last data using Static Cursor:

fetch last from static_cursor

Output:

static-cursor-in-sql-serever-last4.jpg

Fetching 4th data using Static Cursor:

This fetches the specific data giving absolute position:

fetch absolute 4 from static_cursor

Output:

static-cursor-in-sql-serever-absolute5.jpg

Fetching next 2nd data using Static Cursor:

fetch relative 2 from static_cursor

Output:

static-cursor-in-sql-serever-relative6.jpg

Closing the Static Cursor:

We close Static Cursor as in the following

close static_cursor

Dealloting Static Cursor:

We deallocate Static Cursor as following

deallocate static_cursor

© 2019 DotNetHeaven. All rights reserved.