Thanks for this, I wasn't aware that CURSORs could be specified in context.
If you had posed this as a problem I would have said to deallocate and close the cursor in the code immediately preceding your cursor definition.
I'll read up on the syntax today if I get time. Cheers.
---
Note to developers:Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.