Fix SQL statement errors