1) The GROUP BY statement must include all fields in the SELECT not being aggregated or constant cols. 2) There was a missing space causing problems to databases using named parameters.