Fixed a lot of bad SQL syntax