well u need to start thinking set baset. it helps if you begin with one simple set and what applies to that set will apply to all others if you group them correctly.take a look at cursor and try to imagine a set based solution. draw it on a piece of paper.there are a lot of thigs that can be solved with user-defined functions that people use cursors for.directly from BOL:Because @@FETCH_STATUS is global to all cursors on a connection, use @@FETCH_STATUS carefully. After a FETCH statement is executed, the test for @@FETCH_STATUS must occur before any other FETCH statement is executed against another cursor. The value of @@FETCH_STATUS is undefined before any fetches have occurred on the connection.For example, a user executes a FETCH statement from one cursor, and then calls a stored procedure that opens and processes the results from another cursor. When control is returned from the called stored procedure, @@FETCH_STATUS reflects the last FETCH executed in the stored procedure, not the FETCH statement executed before the stored procedure is called.
if it helps you great.Go with the flow & have fun! Else fight the flow