Federico Alzamora Previtali
Subscriber

Your UDF is likely the culprit if it runs fine without it, not in the syntax of the code since it compiles without errors but in how it is set up or what it is doing.

Can you show us what your UDF looks like?