Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@@Fetch_Status?

Status
Not open for further replies.

masterchicker

Programmer
Mar 10, 2004
64
US
DECLARE Employee_Cursor CURSOR FOR
SELECT LastName, FirstName FROM Northwind.dbo.Employees
OPEN Employee_Cursor
FETCH NEXT FROM Employee_Cursor
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Employee_Cursor
END
CLOSE Employee_Cursor
DEALLOCATE Employee_Cursor

What does @@Fetch_Status do? In the sample code above what is its use?
 
if Fetch status =0 means the cursor doesnt fetch any record ie it is in last row

Siva
 
@@FETCH_STATUS is an internal variable representing the status code associated with the retrieval of the most recent row in a cursor. When @@FETCH_STATUS = 0, there are no errors or unusual status. Reaching the end of the cursor is an "error" and @@FETCH_STATUS will not be 0.

-------------------------
The trouble with doing something right the first time is that noboby appreciates how difficult it was.
- Steven Wright
 
In the sample code above what is its use?
To waste resources that are preciously needed by the server. To violate the first tenet of good programming. To delay the learning curve of SQL programmers in set based logic. :)
-Karl


[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top