Friday 8 June 2012

Query using X++ in Ax 2009

Hi Friends,

You know queries are the most easier way to work on than any other statements .

You can derive complex syntax easily by using query.

For first giving us a clear idea we are not going too much deep into the query.

First we have to declare a query by using the following syntax

Query q = new Query();

And we need the following declarations to add datasource, range and to run the query

QueryBuildDataSource qbds;

QueryBuildRange qbr;

QueryRun queryRun;

qbds= q.addDataSource(tablenum(InventTable));
qbr = qbds.addRange(fieldnum(InventTable,ItemId));
qbr1 = qbds.addRange(fieldnum(InventTable,DataAreaId));
qbr1.value(strfmt('(((%3.FromDate >= %1) || (%3.Todate > %1)) && ((%3.Todate<=%2) || (%3.Fromdate<%2)))',Date2StrXpp(LeaveFromDate),
Date2StrXpp(LeaveToDate), q.dataSourceTable(tablenum(InventTable)).name()));

queryRun = new QueryRun(q);
while (
InventTable= queryRun.get(TableNum(InventTable));

info(strfmt("%1" ,InventTable.ItemId));

Vivek Chirumamilla

No comments:

Post a Comment