fix sql query statements