Editing the generated SQL query