Using the OR operator in the Query

 Let us replace the code from the below example: Using the OR operator in the Query  

qbr1.value(queryValue(ProjType::FixedPrice)); 

with the new code:  

qbr1.value(strFmt('((%1 = %2) || (%3 = "%4"))',

fieldStr(ProjTable,Type),

ProjType::FixedPrice+0,

fieldStr(ProjTable,ProjGroupId),

queryValue('TM1')));



Notice that by adding zero to the enumeration in the previous code, we can force the strFmt() function to use the numeric value of the enumeration

another example below:

 
static void projTableJobUsingQuery(Args _args)
{
    Query                   query;
    QueryBuildDataSource    qb, qb1;
    QueryBuildRange         qbr, qbr1;
    QueryRun                qr;
    ProjTable               projTable;
    str                     myvalue = ‘305492-00*';
    ;
 
    query = new Query();
    qb = query.addDataSource(tablenum(ProjTable), "ProjTable");
 
    qbr = qb.addRange(fieldnum(ProjTable, ProjId));
// Here the OR condition is implemented.  
    qbr.value(strfmt(‘(%1.%2 Like "%3") || (%1.%4 Like "%5")’,
                qb.name(),
                fieldstr(ProjTable, ProjId), any2str(myvalue),
                fieldstr(ProjTable, Name),  any2str(myvalue)
                ));
 
 
    qr = new QueryRun(query);
 
    while (qr.next())
    {
        projTable = qr.get(tablenum(ProjTable));
        print projtable.Name;
    }
 
    pause; 
 
}
--------------
from MSDN:
https://msdn.microsoft.com/EN-US/library/aa893981.aspx


static void AddRangeToQuery3Job(Args _args)
{
    Query q = new Query();  // Create a new query.
    QueryRun qr;
    CustTable ct;
    QueryBuildDataSource qbr1;
    str strTemp;
    ;

    // Add a single datasource.
    qbr1 = q.addDataSource(tablenum(CustTable));
    // Name the datasource 'Customer'.
    qbr1.name("Customer");

    // Create a range value that designates an "OR" query like:
    // customer.AccountNum == "4000" || Customer.CreditMax > 2500.

    // Add the range to the query data source.
    qbr1.addRange(fieldNum(CustTable, AccountNum)).value(
    strFmt('((%1.%2 == "4000") || (%1.%3 > 2500))',
        qbr1.name(),
        fieldStr(CustTable, AccountNum),
        fieldStr(CustTable, CreditMax)));

    // Print the data source.
    print qbr1.toString();
    info(qbr1.toString());

    // Run the query and print the results.
    qr = new QueryRun(q);

    while (qr.next())
    {
        if (qr.changedNo(1))
        {
            ct = qr.getNo(1);
            strTemp = strFmt("%1 , %2", ct.AccountNum, ct.CreditMax);
            print strTemp;
            info(strTemp);
        }
    }
    pause;
}



__



Comments