web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Define AND conditions in QueryBuildRange for a same field

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I want to create the corresponding AND conditions in a while loop.

but when while loop run, the condition is OR

2017_2D00_08_2D00_05_5F00_8_2D00_52_2D00_56.png

I want AND instead of OR.

Anyone help me?

Thank all.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    Hi.

    Please use the following code.

    // I feel addRange should be outside whileloop as we dont want to create range for every record

    queryBuildRange = qbdsFinancialTag.addRange(fieldNum(DimensionFinancialTag, Value));

    while(SetEnumerator.moveNext())
    {
    queryBuildRange.value(strFmt('((Value == %1) || (Value == "%2"))',
                                            queryValue("01"),
                                             queryValue("02")));
    }

    Thanks,

    Chaitanya Golla

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    The same field cannot simultaneously have 2 different values, so what good is AND as you have explained it?  

    You want OR to allow for multiple values.  For example, WHERE VALUE IN (N'01',N'02') is identical to WHERE (VALUE = N'01' OR VALUE = N'02').  Perhaps you might express in natural language that you want to select records for value of 01 "and" 02, but in SQL the AND clause means both clauses must be true at the same time, and there are no records where (VALUE = N'01' AND VALUE = N'02'), it's impossible.

    I see also that your query snippet uses NOT, is that part of a NOT EXISTS sub-query?  Perhaps that changes what you mean when you say you want AND?

  • Community Member Profile Picture
    on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    Hi Chaitanya and Sukrut

    Thank for your rep, but I am adding range in while loop, so I can not use the expression that you provide.

  • Community Member Profile Picture
    on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    Hi Brandon, I think you understand my problem.

    For more infomation, I try override method lookup. I want to lookup all value in table DimensionFinancialTag and

    I also want to exclude some values of the DimensionFinancialTag table from my setup, so I use NOT.

    Therefore, I want use AND in my query.

  • Brandon Wiese Profile Picture
    17,788 on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    Removed.

  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at
    RE: Define AND conditions in QueryBuildRange for a same field AX 2012

    Try this

        Query q;
        QueryBuildDataSource qbds;
        QueryBuildRange qbr;
        ;
    
        q = new Query();
    
        qbds = q.addDataSource(tableNum(CustTable));
    
        qbr = qbds.addRange(fieldNum(CustTable, AccountNum));
        qbr.value(SysQuery::valueNot('A') + ',' + SysQuery::valueNot('B'));

    gives

    SELECT * FROM CustTable(CustTable_1) WHERE ((NOT (AccountNum = N'A') AND NOT (AccountNum = N'B')))

    Since you have a loop, you'll have to construct a single concatenated string and then assign that string to a single QueryBuildRange object, but I think it will work.

  • Community Member Profile Picture
    on at
    RE: Define AND conditions in QueryBuildRange for a same field

    Hi Brandon,

    I tried:

    2017_2D00_08_2D00_07_5F00_14_2D00_25_2D00_31.png

    And successful.

    2017_2D00_08_2D00_07_5F00_14_2D00_25_2D00_31.png

    The issue close.

    Thank for your help.

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Define AND conditions in QueryBuildRange for a same field

    Make sure you mark all helpful answers as Verified next to each post to resolve the thread.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans