Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

how to use order by recid in update recordset

Posted on by 425

Hi guys,

I have a serial owner table which has 1 lakh records and i have serial trans table it has more number of records  says 3 lakhs , I have to update counterpartner field in serial owner from serial trans and I have to select the last recid in the child table.

in short, I have to use updaterecordset  and order by recid .


ttsBegin;

while select forUpdate DMSSerialNumOwner
{
select firstOnly * from DMSSerialNumTrans order by recid desc

where DMSSerialNumTrans.SerialNum == DMSSerialNumOwner.SerialNum; //11052016SAM0011
{
     info(strFmt("%1",DMSSerialNumTrans.RecId));
}

DMSSerialNumOwner.counterpartner = DMSSerialNumTrans.counterpartner ;

DMSSerialNumOwner.update;


}

I want to convert the above code in update record set as it has more than 1 lakhs record.

ttscommit;

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: how to use order by recid in update recordset

    For reference, my reply is in a duplicate thread on another forum. (As with database design, duplicity leads to the same thing done several times, plus maintenance cost to keep data consistent.)

  • Suggested answer
    Hariharans87 Profile Picture
    Hariharans87 4,971 on at
    RE: how to use order by recid in update recordset

    Hi Rohit,

    You could create a view for DMSSerialNumOwner table with one computed column for counterpartner.

    Instead of updating, you can go for view. Because, the records will be inserted in the DMSSerialNumTrans table after your updation date. If feel, your requirement is different you can create a view and you can link the view with DMSSerialNumOwner table in the update_recordset statement.

    Refer into this link for last record in view 

    http://dev.goshoom.net/en/2015/06/join-first-line-in-ax-2012/

    If you feel it is only for one time, you can directly update in the SQL Management Studio by using update SQL query. Instead of going for sub query, i feel join will improve the performance.

    SQL:

    UPDATE DMSSerialNumOwner
    SET counterpartner = T.counterpartner
    FROM DMSSerialNumOwner O
    INNER JOIN
    (
    SELECT ROW_NUMBER() OVER (PARTITION BY SerialNum ORDER BY RECID DESC) ROWNUMBER, T.SerialNum, T.counterpartner FROM DMSSerialNumTrans T
    ) T
    ON T.SerialNum == O.SerialNum AND T.ROWNUMBER = 1


    Thanks,

    Hari

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