Ensure WHERE clause is populated before adding AND

Some defensive coding against the possibility of there being empty `WHERE` clauses which would cause the query to fail.