Mark,
If that query is not generating correctly, you may have Macro Signing errors. Can you run the Macro security report (System -> Macros -> Report) and see if it reports any errors? If so you may need to re-sign your macros for your site. I'm not 100% this is it, but it is definitely something to check.