Fix errors in SQL