Your third parameter in the function calls are not quoted.
Also liberally sprinkling the script with
? @ERROR+" "+@SERROR
May indicate where it is breaking.
_________________________
Taxation WITH representation isn't so hot, either!