繁体   English   中英

Dynamics CRM FetchXML 等效于具有子查询聚合列值的 SQL

[英]Dynamics CRM FetchXML equivalent of SQL with sub query aggregate column values

我需要生成一个 CRM 报告(在线,因此必须使用 FetchXML),该报告显示客户以及他们订购的产品数量,每个(预定义)类别都有一列。

这些实体实际上是:客户、订单、订单行和产品。 我在 SQL Server (2008 R2) 中创建了测试数据,以下 SQL 语句生成了正确的结果,但我想知道这在 FetchXML 中是否可行,如果可以,如何实现。

我确实尝试使用 sql2fetchxml.com,但它显示“错误:不支持的字段表达式”

select c.Description, 

(select sum(l1.Quantity) from Customers c1 
Join Orders o1 on o1.CustomerID = c1.ID
Join OrderLines l1 on l1.OrderID = o1.ID
Join Products p1 on l1.ProductID = p1.ID and p1.Category = 'A'
where c1.ID = c.ID) CategoryA_Quantity,

(select sum(l2.Quantity) from Customers c2 
Join Orders o2 on o2.CustomerID = c2.ID
Join OrderLines l2 on l2.OrderID = o2.ID
Join Products p2 on l2.ProductID = p2.ID and p2.Category = 'B'
where c2.ID = c.ID) CategoryB_Quantity,

(select sum(l3.Quantity) from Customers c3
Join Orders o3 on o3.CustomerID = c3.ID
Join OrderLines l3 on l3.OrderID = o3.ID
Join Products p3 on l3.ProductID = p3.ID and p3.Category = 'C'
where c3.ID = c.ID) CategoryC_Quantity

from Customers c

您不能在 CRM 中执行子查询。 您可以执行多个查询,但不能像 ti 定义的那样创建子查询。

虽然不是基于 Dynamics,但您可以在 Power Automate 中创建一个流来复制 SQL 脚本,然后输出报告。 我使用此方法用类似的查询填充门户页面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM