Hi, Using query classes you can do that. e.g.
q = new Query(); ds = q.addDataSource(tablenum(projInvoiceEmpl)); ds.addSelectionField(fieldnum(projInvoiceEmpl,qty),SelectionField::Sum); ds.addSortField(*fieldnum(projInvoiceEmpl,categoryid)*); ds.orderMode(OrderMode::GroupBy); ds.addSelectionField(*fieldnum(projInvoiceEmpl,categoryid*)); Change the bold ones with dynamic fieldid. Regards, Agus On Wed, May 13, 2009 at 12:13 AM, shaakera_b <shaak...@gmail.com> wrote: > > > Hi All, > > I would like to group and sum by fields dynamically in an AX while > statement. Basically I want to sum and group by any field on the table using > a setup table. Example: > > while select sum(qty) from projinvoiceempl > group by CategoryID > { > //Some code which does some stuff with the qty sum > } > > i would like to : > > while select sum(fieldID of sum) from projinvoiceempl > group by (fieldID of category code) > { > //Some code which does some stuff with the qty sum > } > > Is this possible? > > Many thanks, > Shaakera > > >