This is a template that I have been using in SQL server for when I do have to write cursors. Notice that there is only one fetch statement in there which is much slicker than the typical method of initially doing a fetch, with a while condition of while