Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How can I optimize the below update statement to reduce the number of DB calls?

Posted on by 100

Hi,

I have an update statement. Can u suggest me if it can be optimised so the number of db calls can be reduced. I suppose i can't use updare_recordset in this case (or can I use it?). Is there any other way?

while select forupdate AmountCur,salesPrice from projProposalRevenueDetail

     join projProposalRevenue

          where projProposalRevenue.RecId == projProposalRevenueDetail.ProposalRefRecId
          && projProposalRevenue.ProposalId == _proposalId
     join TotalSalesAmountCur from projRevenueTrans
          where projRevenueTrans.TransId == projProposalRevenue.TransId
          && projRevenueTrans.ProjId == _projId
{
     projProposalRevenueDetail.AmountCur = (projRevenueTrans.TotalSalesAmountCur/(_totalHrsSalesPrice + totalFeeSalesPrice)) * _Amount;
     projProposalRevenueDetail.salesPrice = projProposalRevenueDetail.AmountCur / minOne(projProposalRevenue.Qty());
     projProposalRevenueDetail.update();
}

Thanks.

*This post is locked for comments

  • Verified answer
    Blue Wang Profile Picture
    Blue Wang on at
    RE: How can I optimize the below update statement to reduce the number of DB calls?

    Hi JayVee,

    The records in the updated database are as follows.

    1. Loop through all records and update them in the database.

    (Creating the total number of calls to database records reduces performance).

    This fits the update function.

    2. Call only one database and update all records in this call.

    (Ways to improve performance).

    This option is to update_recordset, which allows you to update multiple rows in a single trip to the server.


    You can also try use Query(),and then update.

    https://docs.microsoft.com/en-us/dynamicsax-2012/developer/how-to-create-queries-by-using-x

  • JayVee13 Profile Picture
    JayVee13 100 on at
    RE: How can I optimize the below update statement to reduce the number of DB calls?

    Sorry, I was able to use update_recordSet only thing is I need to get the Qty directly instead of using the projProposalRevenue.Qty()

    Here what the final statement looked like

    update_recordset projProposalRevenueDetail

           setting

               AmountCur = (projRevenueTrans.TotalSalesAmountCur/(_totalHrsSalesPrice + _totalFeeSalesPrice)) * _lnFeeAmount,

               salesPrice = ((projRevenueTrans.TotalSalesAmountCur/(_totalHrsSalesPrice + _totalFeeSalesPrice)) * _lnFeeAmount) / projRevenueTrans.Qty

           join projProposalRevenue

               where projProposalRevenue.RecId == projProposalRevenueDetail.ProposalRefRecId

               && projProposalRevenue.ProposalId == _proposalId

           join projRevenueTrans

               where projRevenueTrans.TransId == projProposalRevenue.TransId

               && projRevenueTrans.ProjId == _projId;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans