If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

You may be able to put this code into a stored procedure and call the procedure from a UDF.

You may even let that stored procedure just declare and open the cursor, and return a handle to the cursor, so that the fetches happen in the caller.
Not sure though whether a UDF is able to do the FETCHes.