Fix SQL syntax issues