Queries in Dynamics AX

November 13, 2016 | Author: sankarmnusa1 | Category: N/A
Share Embed Donate


Short Description

Queries in Dynamics AX...

Description

Queries in Dynamics AX 2012 Types of Queries:

There are three types of queries in dynamics ax 2012: 1. Inline Queries 2. AOT Queries 3. Queries objects and API 1. Inline Queries: Inline queries are similar to the LINQ queries in .NET. In inline queries, you need to create the table buffer. Table Buffer is quite similar to the objects in classes. In Dynamics Ax tables can also be treat as a classes where you can write your own methods. Below is the simple example of inline queries. CustTable custTable; select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000"; info(custTable.AccountNum); I you want to show all the records in the info box than we use while statement while select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000"; { info(custTable.AccountNum); } We can also use aggregate functions in inline queries. Here is the example given below: select count(AccountNum) from custTable where custTable.AccountNum>"1000"; info(custTable.AccountNum); Joins in Inline Queries: Lets make it little bit more interesting by using joins: HcmBenefit hcmBenefit; HcmBenefitPlan hcmBenefitPlan;

while select * from HcmBenefit join HcmBenefitPlan where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId { info("%1,%2",hcmBenefit.BenefitPlan,hcmBenefitPlan.RecId); }

Group By Clause in Inline Queries:

Group by clause is basically use when we use aggregate functions.Lets see an example: while select count(RecId) from hcmBenefit join Description from hcmBenefitPlan group by hcmBenefit.BenefitPlan,hcmBenefitPlan.Description where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId { info(strfmt("%1,%2",hcmBenefit.RecId,hcmBenefitPlan.Description)); }

Inline Queries -Select Options :

Simple Insert,Update,Delete: Insert: Student student; student.name="muhammad zahid"; student.insert(); Update: select forupdate from student where student.name=="muhammad zahid" if(student.RecId>0) { ttsbegin; student.name="Baber Tareen"; student.update(); ttscommit; } note:The if check was only to check that if the record exist or not that i have fetch.You can remove this if check if you want. Delete: select forupdate from student where student.name="Baber Tareen"; if(student.RecId>0) { ttsbegin; student.delete(); ttscommit; } Insert And Update multiple records at a Time: For inserting multiple data at a single time we use insert_recordset and for updating multiple data at a single time we use update_recordset update record set insert_recordset: insert_recordset myTable(myNum,mySum) select myNum,sum(myValue) from anotherTable group by myNum where myNum
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF