web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to use order by recid in update recordset

(0) ShareShare
ReportReport
Posted on by 439

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

I have the same question (0)
  • Suggested answer
    Hariharans87 Profile Picture
    36 on at

    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

  • Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at

    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.)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans