You need to construct your SQL query in a manner that is syntactically correct. In this case, it looks like just tacking a WHERE clause on the end of the default SQL statement isn't going to work. Why don't you figure out what the entire query is supposed to be and use that instead?