Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Cursor FunctionsRSS Feeds

@@FETCH_STATUS - FETCH STATUS Function

Posted By: Sarita Patel     Category: SQL Server     Views: 12412

This article explains about @@FETCH_STATUS function in sql server with examples.

@@FETCH_STATUS function determines whether FETCH keyword has successfully retrieved a row from the current cursor. The value of @@FETCH_STATUS is undefined before any fetches have occurred on the connection.

This function can have one of the three values:

Return Value

Description

0

FETCH statement was successful.

-1

FETCH statement failed or the row was beyond the result set.

-2

Row fetched is missing.



Syntax of @@FETCH_STATUS Function :


@@FETCH_STATUS

Return type of @@FETCH_STATUS function is integer.



Examples of @@FETCH_STATUS Function :

Example 1 : Use of @@FETCH_STATUS function

DECLARE Customer_Cursor CURSOR FOR
SELECT ContactName FROM Customers
OPEN Customer_Cursor 
FETCH NEXT FROM Customer_Cursor 
WHILE @@FETCH_STATUS = 0
BEGIN
   FETCH NEXT FROM Customer_Cursor 
END
CLOSE Customer_Cursor 
DEALLOCATE Customer_Cursor 


Above cursor displays each customer name one by one.  

  
Share: 

 
 

Didn't find what you were looking for? Find more on @@FETCH_STATUS - FETCH STATUS Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of @@FETCH_STATUS - FETCH STATUS Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!