Fix invalid sql statements