Wednesday, April 14, 2010

How to use the like operator with string comparisons

If you programmed SQL statements in Ax, you've probably used the like operator in your statement.
Like (!) this

select * from CustTable where CustTable.Name like 'A*'

Something less known about the like operator, is that you can also use it in string comparisons.
Example:

static void LikeOperator(Args _args)
{ str test;
;

test="Dynamics Ax";

if(test like "Dynamics*")
info('OK!');
}




You can use the like operator with your well known wildcards as * and ?
So for example

test like "D?namics*"


As such, it's use is complimentary to the likes of functions as strscan and strfind.

2 comments:

  1. It is not working.

    static void Job3(Args _args)
    {
    str testString = 'HOURS THIS WEEK';
    str wildcardString = 'HOURS%';
    str result;

    if (testString like wildcardString)
    {
    result = ' IS like ';
    }
    else
    {
    result = ' is NOT like ';
    }

    info(strFmt('testString %1 %2 wildcardString %3', testString, result, wildcardString));
    }

    testString HOURS THIS WEEK is NOT like wildcardString HOURS%

    ReplyDelete
    Replies
    1. My bad.
      I used % (as is used in the Wildcard field in DimensionConstraintNodeCriteria and DimesionRuleCriteria) instead of *. It works with *.

      Delete