I'm not sure as to why it uses a global variable but here are my thoughts on the subject.
"
@@FETCH_STATUS
is global to all cursors on a connection"
http://msdn.microsoft.com/en-us/library/ms187308.aspx[
^]
This means that you do have to be aware of the behaviour such variable type. You can create a problem if your cursor calls a stored procedure which implements another cursor as the
@@FETCH_STATUS
value will be invalid when returning from the stored procedure. The trick is to make sure you always evaluate the result of a fetch immediately after executing the fetch.
But as is often the way, you can do things a number of ways. You can check the
fetch_status
of any given cursor using the
sys.dm_exec_cursors
management function.
Read here for more details on this function.
http://msdn.microsoft.com/en-us/library/ms190346.aspx[
^]