Like operator in x++

Sometimes we have to search some records in a table having a field that satisfies a regular expression. For  istance, if i want to retrieve all Customer having the name starting by “A” i should fetch al Record of CustTable, having the Name field that match with the expression “A*”.

To perform this kind of research we can use the operator like that we can insert both in query and in rest of the code. But there is an important issue. The behaviour of this operator used in queries is different from the behavior of the same operator used out of a query.

into queries:

  • “ABC123” like “ABC*” return false value.
  • “ABC123” like “ABC%” return true value.

Out of queries:

  • “ABC123” like “ABC*” return true value.
  • “ABC123” like “ABC%” return false value.

Namely, the characters “*” and “%” exchange their semantics.

The ax user is used to insert “*” in the form to filter the record or insert any kind of query on user side. Then the developer has to “Translate” the regulare expression replacing the “*” character with “%” character and perform the query :

CustTable custTable;
str valueInsertedByUser = "ABC*";
select custTable where CustTable.Name like strReplace(valueInsertedByUser,"*","%");
return custTable;

The task becomes more complicated when the the regular expression is in a table field, and we have to retrieve a record having a regular expression (written by the user, with “*”) that match a particular string value. For example : I have three record in a table:


I Have to search the record matching  to the string B34545644, that’s the second.

In that case , since i cannot perform a string replacement directly on the DBServer i have to fetch all records and use the like operator as out of a query:

Example table table;
str searchingValue = "B34545644";
while select table
    if(searchingValue like table.field) return table;

Since Like operator in this case is used out of a query, it works through “*” and no replacement is needed.