I find it hard to believe it gets that far. There are many strings surrounded by double quotes inside your statement, which is a double quoted string. The configuration compiler should be blowing up around
plantCode",
Escape them, use single quotes if SQL allows it, or put the statement in a file and reference that.