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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Previous Record in a Select Statement

(0) ShareShare
ReportReport
Posted on by

Dear Friends,

In Ax (X++), we can use next option in While Select statement to move to next record. But, for move to previous record, what we have to use. (ex.)

For move to next record....

While Select tablename where tablename.condition

{

statement...;

next tablename;

}

This moves to next record

As it is what shall we use to move to previous record.

 

Thanks,

Rajkumar.G

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at
    RE: Previous Record in a Select Statement

    You could add desc to your select, in order to select in reverse order (msdn.microsoft.com/.../aa656402.aspx)

    There is no way to get the previous record from a select statement.

  • Community Member Profile Picture
    on at
    RE: Previous Record in a Select Statement

    Hi Palle,

    Thanks,

    But, you know that we are using move operations (MoveFirst, MoveNext, MovePrevious, MoveLast) in VB6.0 and in VB.net also. Especially in SQL itself we can use.

    Why can't in axapta. Please give suggestions.

  • PA-22040759-0 Profile Picture
    6,194 on at
    RE: Previous Record in a Select Statement

    It's simply not a part of the X++ language.

  • Hariharans87 Profile Picture
    3 on at
    RE: Previous Record in a Select Statement

    There is no need to use next statement in the while statement, instead you can use continue statement because while loop automatically move to next record. If you use next statement in while, it will simply ignore next record not move to next record.

    Refer into this link msdn.microsoft.com/.../aa845764.aspx

    If you want to refer previous record, you can use select statement inside the while loop.

    Please let me know your scenario, we will try to give the suggestion.

  • Suggested answer
    botten Profile Picture
    320 on at
    RE: Previous Record in a Select Statement

    static void Job1(Args _args)
    {
    CustTable custTable;
    CustTable previous;
    Counter counter;
    container con;

    while select custTable
    {
    con = conIns(con, 1, custTable);
    }

    for (counter = 1; counter < conLen(con); counter++)
    {
    custTable = conPeek(con, counter);
    if (counter > 1 && counter < conLen(con))
    {
    previous = conPeek(con, counter-1);
    }
    info(strFmt("previous: %1, current: %2", previous.name(), custTable.name()));
    }
    }

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Previous Record in a Select Statement

    I would be *very* careful before copying the whole content of the table to memory, especially if not all records are actually needed (so the fetching itself would be a waste of resources).

    There are many other options that don't require fetching the whole table and keeping all records in memory at once. For example, you could use a view with ROW_NUMBER() and ask for a specific index, put the data into a temporary table and so on.

    But most likely the question came from not understanding how to design solutions for AX and implementing something like MovePrevious() isn't really necessary with a more suitable design.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans