fixed sql syntax errors for allocated query