@@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:
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.
This function can have one of the three values:
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.