【问题标题】:How can I convert this T-SQL to Fetch-XML?如何将此 T-SQL 转换为 Fetch-XML?
【发布时间】:2013-09-10 09:40:35
【问题描述】:

我想在 Dynamics CRM 报告中使用此 SQL。我不知道如何将其转换为 Fetch-XML。

select p.ProductNumber "Plan Number",p.Name,p.price "Monthly Rate",count(*) "Group", '0' "Direct Debit"
from contact c,product p 
where c.integ_schemeid = p.ProductId
and c.ParentCustomerId is not null
group by p.ProductNumber,p.Name,p.price

union

select p.ProductNumber "Plan Number",p.Name,p.price "Monthly Rate", '0' "Group", count(*) "Direct Debit"
from contact c,product p 
where c.integ_schemeid = p.ProductId
and c.ParentCustomerId is null
group by p.ProductNumber,p.Name,p.price

http://www.sql2fetchxml.com 在这种情况下失败。

【问题讨论】:

    标签: tsql dynamics-crm-2011 dynamics-crm fetchxml


    【解决方案1】:

    您无法将该查询转换为 FetchXML,因为不支持联合。如果可能,您需要做的是考虑将查询合并为 1。即使这意味着复制列并在报告中使用条件语句来显示相关数据。例如,如果您将查询简化为:

    select p.ProductNumber "Plan Number", p.Name, p.price, c.ParentCustomerId
    from product p 
    inner join contact c on c.integ_schemeid = p.ProductId
    

    这可以转换成下面的fetchxml:

    <fetch mapping="logical">
      <entity name="product">
        <attribute name="ProductNumber" alias="Plan Number" />
        <attribute name="Name" />
        <attribute name="price" />
        <link-entity name="contact" to="ProductId" from="integ_schemeid" alias="c" link-type="inner">
          <attribute name="ParentCustomerId" />
        </link-entity>
      </entity>
    </fetch>
    

    然后,由于您在 1 个数据集中拥有所有数据,包括具有 null ParentCustomerIds 的联系人,因此您可以在报告中而不是在查询中进行分组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2019-12-05
      相关资源
      最近更新 更多