Fixing SQL queries on fix_quota_script