Sql FetchXML中具有多个条件的左外部联接
我正在尝试使用多个条件在FetchXML中进行左外连接 以下是我试图实现的大致SQL:Sql FetchXML中具有多个条件的左外部联接,sql,dynamics-crm,fetchxml,Sql,Dynamics Crm,Fetchxml,我正在尝试使用多个条件在FetchXML中进行左外连接 以下是我试图实现的大致SQL: SELECT incident.*, externalCheck.* FROM incident LEFT OUTER JOIN externalCheck ON externalCheck.incidentId = incident.incidentId AND externalCheck.checkType = 1 AND externalCheck.isLatest = 1; 注意:这应
SELECT incident.*, externalCheck.*
FROM incident
LEFT OUTER JOIN externalCheck
ON externalCheck.incidentId = incident.incidentId
AND externalCheck.checkType = 1
AND externalCheck.isLatest = 1;
注意:这应该总是返回1:1的关系,因为我们的业务逻辑要求每个检查类型只有一个isLatest
下面是我的FetchXML:
<entity name="incident">
<all-attributes />
<link-entity name="externalCheck" from="incidentId" to="incidentId" link-type="outer">
<filter type="and">
<condition attribute="checkType" operator="eq" value="1" />
<condition attribute="isLatest" operator="eq" value="1" />
</filter>
<all-attributes />
</link-entity>
</entity>
问题
问题在于,连接右侧为null(即没有externalCheck记录)的事件记录不会被返回,而在左侧外部连接中,我希望即使连接右侧为null,事件记录也会被返回
我怀疑FetchXML正在将我的过滤器转换为WHERE子句,而不是向ON子句添加条件
问题
有人能证实发生了什么,以及可能的解决办法吗?你的怀疑是正确的。但你可以从中有所克服 Fetchxml是灵活的&下面的代码片段将给出带有multiple子句的左外部联接的结果
<entity name="incident">
<all-attributes />
<link-entity name="externalCheck" alias="ext" from="incidentId" to="incidentId" link-type="outer">
<filter type="and">
<condition attribute="checkType" operator="eq" value="1" />
<condition attribute="isLatest" operator="eq" value="1" />
</filter>
</link-entity>
<filter>
<condition entityname="ext" attribute="externalCheckid" operator= "null" />
</filter>
</entity>
你好,阿伦。谢谢你的回答。我已经尝试了XML的各种版本,但是我一直得到一个错误,即“entityname”不是该条件的有效属性。在没有entityname的情况下,将运行提取,但它对返回的行数没有影响。看起来它应该可以工作,但XrmToolBox正在抱怨该属性。“entityname属性不是链接实体的有效属性。”尽管我已在条件节点上添加了该属性,但这一点仍然存在。奇怪。@MarkMicallef忘了xrmtoolbox,它是在你的代码中执行的&获取结果吗?