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 :
Microsoft Dynamics AX (Archived)

Complex Query range with combined && clause

(0) ShareShare
ReportReport
Posted on by

Hello

I would like to add a range to a query in order to obtain the following equivalent result in SQL :

select * from CUSTTRANS where not((custtrans.TRANSTYPE = 15) and (CUSTTRANS.LASTSETTLEVOUCHER = ''))


Here is what I have done so far, but does not return the correct query :

str rangeStr;

    rangeStr = strFmt('!((%1 == %2) && (%3 == ""))',
        fieldStr(CustTrans, TransType),
        any2int(LedgerTransType::Payment),
        fieldStr(CustTrans, LastSettleVoucher));
    
    CustTrans_ds.query().dataSourceTable(tablenum(CustTrans)).addRange(fieldnum(CustTrans, TransType)).value(rangeStr);
    super();

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    First of all you need braces around the whole advanced query criteria. Then try negating the two brackets individually, see if that works. Something like: (!(A == B) && !(B == C))

  • Community Member Profile Picture
    on at

    I get a different result, but still doesn't work. It also provokes the following error : Query extended range failure: The '!' operator can only be used with the 'like' keyword.

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Pellandk,

    Try this 

    rangeStr = strFmt('((%1 != %2) && (%3 != ""))',
            fieldStr(CustTrans, TransType),
            any2int(LedgerTransType::Payment),
            fieldStr(CustTrans, LastSettleVoucher));
    
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Right, you can only negate a LIKE statement, but you can use the not equal like Ievgen suggested in advanced query expressions.

  • Cengiz UCAR Profile Picture
    on at

    Hi,

    When you pass ! into brace && should become || (I mean AND becomes OR)

    Regards,

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans