>>>I've seen SQL get very confused in UNIONs when you don't explicitly specify your field names.
>>
>>I'll try, but I think the problem is with the derived table. Most likely I need to move it to a separate cursor.
>
>I would try first changing the alias of the select in the union, you have both alias as V and that might be confusing the parser?
Same error.
If it's not broken, fix it until it is.
My Blog