I don't know if you're using SQL Server as your backend, but the idea is to spit out the query string you're submitting and try running it somwhere outside your code. That usually points out syntax ...
Some results have been hidden because they may be inaccessible to you
Show inaccessible results