and if it's returning a 1 on success, verify that is the correct exit code for a success on the UDF and modify the loop so it reflects the proper code. it sounds like it's excuting correctly but @ERROR <> 0 is not the correct condition to check for