SELECT cnt(wo_itemno) as items, i_key, t_key, contractor ; FROM v_woitems ; INTO CURSOR tWoinvcont ; ORDER BY t_key ; GROUP BY t_key, i_key, contractorAll of the items in the SELECT statement except for the fields being aggregated need to be in the group by clause.