AX – D365FO – Select TOP n rows in select statement – X++

You can only retrieve 1, 10, 100, 1000 records from a select statement using firstonly syntax (like shown below)

while select firstonly100 rent
    order by PostedDate desc
    where (rent.PostedDate > td && rent.RentalOrderStatus == z_RentalOrderStatus::Posted)
       || rent.RentalOrderStatus == z_RentalOrderStatus::Approved
{
    info("orders");
}

If you want to get different number of rows you can implement a counter in the while statement and force the code to stop as it reaches a prefixed limit value like show in code below.

int counter;

int limit = 5;

CustTable custTable;


while select custTable
order by custTable.AccountNum

{

   counter++;

   if(counter>=limit) break;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s