Every time I to work with explicit SQL queries, first thing I do is checking the SQL syntax in some database client app. Only when I know that it's fully correct, I implement it in my code.