Contents

How to use operator "or" in QueryBuildRange

Contents

This blog post is show how to apply OR conditions in query build ranges in a simple way on same field in a table. Let’s see the simple query :

1
select * from CustTable where AccountNum == '2001' || AccountNum == '2002'

We can find out solutions on MSDN by using expression in query ranges, but as it has lot of specifications which needs to be followed. However there is a simple way to do it :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
static void Job12(Args _args)
{
    CustTable cust;
    Query query = new Query();
    QueryBuildDataSource qbds;
    QueryBuildRange queryRange1, queryRange2;

    qbds = query.addDataSource(tableNum(CustTable));

    queryRange1 = qbds.addRange(fieldNum(CustTable, AccountNum));
    queryRange1.value('1168201');

    queryRange2 = qbds.addRange(fieldNum(CustTable, AccountNum));
    queryRange2.value('9034518');

    qbds.addRange(fieldNum(CustTable, createdDateTime));
    queryRange1.value(queryValue(dateNull());
    qbds.addRange(fieldNum(CustTable, createdDateTime));
    queryRange1.value(queryRange(today()+1, dateMax()));

    info(qbds.toString());
}

Result in string format as below image:

1
SELECT * FROM CustTable(CustTable_1) WHERE ((AccountNum = N'1168201') OR (AccountNum = N'9034518'))

Ref: https://learn.microsoft.com/en-us/dynamicsax-2012/developer/using-expressions-in-query-ranges?redirectedfrom=MSDN