AX / D365FO – Using “Not Like” in X++ select statements

If you want to use wild-cards in Ax, you can write a SQL statement with a LIKE keyword

SalesTable salestable;

select firstonly salestable
where salestable.salesId like '123*';

But if you want to use NOT LIKE you can do in 3 different ways :

SalesTable salestable;

select firstonly salestable
where !(salestable.salesId like '123*');
SalesTable salestable, salestableExists;

select firstonly salestable
    notExists join salestableExists
    where salestable.salesId == '123*';
Query query = new Query();
QueryRun queryRun;


query.addDataSource(tableNum(Salestable)).addRange(fieldNum(SalesTable, SalesId)).value('!123*');

queryRun = new QueryRun(query);
if(queryRun.next())
{
.....
}

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