Not sure we'll be able to help you by close of business but I have a concern. I know substring is the core function and left/right are just wrappers, but the error message is usually explicit as to which one of the three are failing.
There is no substring() in your snippet. I fear we'd need to see the entirety. I'm concerned that it might be buried in a function of some kind.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA