SQL fixes
Minor fixes