Thursday, October 24, 2013

ExistsJoin

List all the customers that has entries in the Sales table.

    Query                   query;
    QueryBuildDatasource    datasource,SalesDataSource,CustomerDataSource;
    QueryRun   queryrun;
    CustTable custtable;
    SalesTable salesTable;
    query = new Query();
    CustomerDataSource  = query.addDataSource(tableNum(CustTable ));
    SalesDataSource  = CustomerDataSource.addDataSource(tableNum(SalesTable ));
 
    SalesDataSource.joinMode(JoinMode::ExistsJoin   );
 
    SalesDataSource.relations(false);

    SalesDataSource.addLink(fieldNum(CustTable, AccountNum),
    fieldNum(SalesTable  , CustAccount ));
    queryrun = new QueryRun(query);
    while(queryRun.next())
    {
        custtable = queryRun.get(tablenum(CustTable ));
        Info(custtable.AccountNum);
    }

List customers who has entries in the project table
    Query q;
    QueryBuildDataSource        vrfQBDSCustTable;
     QueryBuildDataSource        qbr1;
   
    q = new Query();
    vrfQBDSCustTable = q.addDataSource(tableNum(CustTable));
    qbr1 = vrfQBDSCustTable.addDataSource(tableNum(ProjTable));
    qbr1.joinMode(JoinMode::ExistsJoin);
    qbr1.relations(true);
   
    info(q.xml());

No comments:

Post a Comment