Something like this:
select invoiceno, partno, sum(quantity) as qty
group by invoiceno, partno
The simple answer is not to use Query/400 to do SQL functions — use SQL reporting. That is, create a Query Manager query instead. At least, that’s the simple answer if the SQL Development Kit is on the system.
Query/400 has been obsolete for what must be 15 years by now. QM queries and forms have long surpassed the capabilities of Query/400. Even if neither Query/400 nor the SQL Development Kit is installed, QM queries and forms can still be created. The Query Management Programming manual describes the source language.
However, there are shortcuts by way of CRTQMQRY, DLTQMQRY, RTVQMQRY and WRKQMQRY, as well as CRTQMFORM, DLTQMFORM, RTVQMFORM and WRKQMFORM. These are on all systems.
And if Query/400 is available, much of the basic QM query and form work can be done with it. RTVQMQRY and RTVQMFORM can retrieve enough of the Query/400 definition into QM source members to provide a start.