zoukankan      html  css  js  c++  java
  • dynamics Ax 2009 实现 union 效果

    Ax中多表关联仅提供Inner Join/Outer Join/Exist join/Not Exist join,而么有union,可以通过Query来实现.

    例如 Sql:

    select ItemType,GoodsName from table1 where TransDate between g_DateB and g_DateE
    union
    select ItemType,GoodsName from table2 where TransDate between g_DateB and g_DateE

    1 实现[ from table1 ]
        qbd = query.addDataSource(tableNum(table1));
    2 实现[ select ItemType,GoodsName ]
        qbd.addSelectionField(fieldnum(table1,ItemType));
        qbd.addSelectionField(fieldnum(table1,GoodsName));
    3 实现[ where TransDate between g_DateB and g_DateE ]
      qbd.addRange(fieldnum(table1,TransDate)).value(strfmt("%1..%2", g_DateB,g_DateE));
    4 实现[ union ]
        query.queryType(QueryType::Union);
      
    代码:
       Query query;
        QueryRun qr;
        QueryBuildDataSource qbd;
        QueryBuildDataSource qbd2;
        Table1 newTable;

        qbd = query.addDataSource(tableNum(table1));
        qbd.addSelectionField(fieldnum(table1,ItemType));
        qbd.addSelectionField(fieldnum(table1,GoodsName));
        qbd.addRange(fieldnum(table1,TransDate)).value(strfmt("%1..%2", g_DateB,g_DateE));

        qbd2 = query.addDataSource(tablenum(table2));
        qbd2.addSelectionField(fieldnum(table2,ItemType));
        qbd2.addSelectionField(fieldnum(table2,GoodsName));
        qbd2.addRange(fieldnum(table2,TransDate)).value(strfmt("%1..%2", g_DateB,g_DateE));


        qbd2.addRange(fieldnum(table2,RecId)).
                value(strfmt("((%1 > %2) || (%3 > %4) || (%5 > %6))",
                fieldstr(table2,Qty),queryValue(0),
                fieldstr(table2,Weight),queryValue(0),
                fieldstr(table2,Volume),queryValue(0)));// OR Condition

        query.queryType(QueryType::Union);
        qr = new QueryRun(query);
        while(qr.next())
        {
         newTable = qr.get(tableNum(table1));
         //do something...
      }

    非有希望才坚持,坚持才会有希望
  • 相关阅读:
    Go的50坑:新Golang开发者要注意的陷阱、技巧和常见错误[2]
    Go的50坑:新Golang开发者要注意的陷阱、技巧和常见错误[1]
    进程和线程
    Linux 技巧:让进程在后台可靠运行的几种方法
    Linux 网络命令必知必会之 tcpdump,一份完整的抓包指南请查收!
    这些好用的 Chrome 插件,提升你的工作效率
    golang学习笔记-go mod的使用
    性能监控和分析工具---nmon
    Jenkins
    程序员画图工具总结
  • 原文地址:https://www.cnblogs.com/eugenewu0808/p/2160914.html
Copyright © 2011-2022 走看看