How to use Having in Ax 2012

 

static void Johnkrish_Have(Args _args)
{
Bill_TabMethod_1 billtab;
while select sum(Quatity) from billtab group by CustName where billtab.Quatity >=5
info(strFmt(“Group %1 %2”,billtab.CustName,billtab.Quatity));

}

static void Johnkrish_QueryHaving(Args _args)
{
Query query;
QueryBuildDataSource datasource;
QueryBuildRange range;
QueryHavingFilter havingFilter;
QueryRun queryRun;
int counter = 0, totalCounter = 0;
Bill_TabMethod_1 billtab;

query = new Query();
datasource = query.addDataSource(tableNum(Bill_TabMethod_1));
datasource.addSelectionField(fieldNum(Bill_TabMethod_1, Quatity),SelectionField::Sum);
datasource.orderMode(OrderMode::GroupBy);
datasource.addGroupByField(fieldNum(Bill_TabMethod_1, CustName));

havingFilter = query.addHavingFilter(datasource, fieldStr(Bill_TabMethod_1, Quatity),AggregateFunction::Sum);
havingFilter.value(‘>=5’);

queryRun = new QueryRun(query);
while (queryRun.next())
{
billtab = queryRun.getNo(1);
info(strFmt(“Group %1: %2”, billtab.CustName, billtab.Quatity));
}
}

Advertisements

One comment on “How to use Having in Ax 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s