【问题标题】:Convert from SQL to XML?从 SQL 转换为 XML?
【发布时间】:2017-05-01 02:12:20
【问题描述】:

我正在努力将其转换为 XML,有人可以建议显示相同的信息,但这次是在 XML 中。

SQL 在下面

select so.ordernumber, 
       sod.productidname, 
       so.statuscode, 
       so.statuscodename, 
       sod.quantity, 
       sod.quantityshipped, 
       ip.pcssu_quantityavailable, 
       so.pcssu_stockavailable     
from FilteredSalesOrder so
inner join FilteredSalesOrderDetail sod 
    on sod.salesorderid = so.salesorderid
inner join filteredaccount a 
    on a.accountnumber = so.pcssu_servicecentrecode
inner join Filteredpcssu_inventoryproduct ip 
    on ip.pcssu_product = sod.productid 
    and ip.pcssu_servicecenter = a.accountid
where so.statuscode = '141560004'
and ip.pcssu_quantityavailable >= sod.quantity - sod.quantityshipped

我设法在没有 and 语句的情况下将上述大部分内容转换为 XML,转换器在提及时抛出了一个错误

错误:WHERE 子句仅支持主要实体的条件,请考虑将别名“ip”的条件移至其 JOIN 的 ON 子句。 请注意,由于 FetchXML 查询的限制,并非所有 SQL 查询都可以转换为 FetchXML。

请建议移动 and 加入 and 抛出错误的语句是

where so.statuscode = '141560004'
and ip.pcssu_quantityavailable >= sod.quantity - sod.quantityshipped

下面是没有AND的转换XML

<fetch mapping="logical" version="1.0">
  <entity name="SalesOrder">
    <attribute name="ordernumber" />
    <attribute name="statuscode" />
    <attribute name="statuscodename" />
    <attribute name="pcssu_stockavailable" />
    <filter>
      <condition attribute="statuscode" operator="eq" value="141560004" />
    </filter>
    <link-entity name="SalesOrderDetail" from="salesorderid" to="salesorderid" alias="sod" link-type="inner">
      <attribute name="productidname" />
      <attribute name="quantity" />
      <attribute name="quantityshipped" />
      <link-entity name="pcssu_inventoryproduct" from="pcssu_product" to="productid" alias="ip" link-type="inner">
        <attribute name="pcssu_quantityavailable" />
      </link-entity>
    </link-entity>
    <link-entity name="account" from="accountnumber" to="pcssu_servicecentrecode" alias="a" link-type="inner" />
  </entity>
</fetch>

【问题讨论】:

  • 您能否举例说明您希望输出的外观?另外,你说你在挣扎——这是否意味着你可以向我们展示一些尝试?您是尝试在 SQL 中执行此操作,还是使用其他编程语言?

标签: sql dynamics-crm fetchxml


【解决方案1】:
ip.pcssu_quantityavailable >= sod.quantity - sod.quantityshipped

基本上这种基于算术公式的过滤器在fetchxml中是无法实现的。在某些情况下,您需要汇总字段或计算字段来实现相同的效果。

否则,您可以自行获取结果集并在代码中过滤/计算。

【讨论】:

    【解决方案2】:

    作为mysql 命令行工具的一部分,有一个简单的 xml 输出 - 请参见此处 - XML output from MySQL

    命令行参数--xml - 但输出看起来像这样&lt;row&gt;&lt;field name="id"&gt;1&lt;/field&gt;&lt;field name="name"&gt;myname&lt;/field&gt;&lt;/row&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 2018-03-28
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多