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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Dynamics 365: use Next table

(0) ShareShare
ReportReport
Posted on by

Description:

i have some code about use select statement, so i want to know whether it will occur error when we use next table which table is no data exist? and if it will error in second next statement or not, maybe it will occur in first next statement if we don't use noFetch keyword? and can you give me some detailed suggestions?

For example:

{

 select noFetch * from table;

 next table;

next table;

next table;

}

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at

    Hi Apple,

    You will get exception here

    pastedimage1590725158865v1.png

    pastedimage1590725340149v1.png

  • zhifeng Profile Picture
    on at

    If you must traverse several records, it's more appropriate to use a while select statement. Please refer:docs.microsoft.com/.../xpp-data-query

    select statements

    The select statement fetches or manipulates data from the database. All select statements use a table variable to fetch records. This variable must be declared before a select statement can be run. The select statement fetches only one record, or field. To fetch additional records, you can use the next statement. The next statement fetches the next record in the table. If no select statement precedes the next statement, an error occurs. If you use a next statement, don't use the firstOnly find option. If you must traverse several records, it's more appropriate to use a while select statement. The results of a select statement are returned in a table buffer variable. If you use a field list in the select statement, only those fields are available in the table variable. If you use aggregate functions, such as sum or count, the results are returned in the fields that you perform the sum or count over. You can count, average, or sum only integer and real fields.

  • Liya Cheng Profile Picture
    on at

    yeah, it will get error, so i want to know that is it reasonable?

  • Liya Cheng Profile Picture
    on at

    yeah, i know, but what i want to know is it will get error when i use multiple next statement which the table is no data.

    i want to know the behavior(get the error) is correct.

  • Verified answer
    WillWU Profile Picture
    22,361 on at

    Hi Apple,

    I think it is logical and reasonable.This is similar to the nullpointer exception, and you did't get any object there.

    What's your requirement?

    As Kevin said, you could use while select statement, does it meet your needs?

    And you could have a look at this old thread:

    community.dynamics.com/.../x-while-select-next-record

  • Liya Cheng Profile Picture
    on at

    ok, thanks. i only need to verify it is reasonable. because i have a one test, it should get error when use next statement, if it is correct, i can  sure the behavior is correct for my test.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    select myTable;
    
    while (myTable)
    {
        // do somthing
        next myTable;
    }

    Here's how you should do it, if you don't want to use a while select statement:

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans