如何在FetchXML中创建条件可选

Mah*_*mal 6 dynamics-crm reporting-services fetchxml dynamics-crm-2011 dynamics-crm-2013

我有一些性能非常慢的SQL报告,因此我们将它们全部转换为FetchXML,但所有SQL报告都具有可选的所有条件,如下所示:

SELECT 
  ...
FROM ...
WHERE (@operator          = 'All' OR Operator          = @operator)
  AND (@new_gen_comp_name = 'All' OR new_gen_comp_name = @new_gen_comp_name)
  ...
Run Code Online (Sandbox Code Playgroud)

在参数值中,All如果用户选择此值,则存在一个值,该条件将被忽略,因此它将从该字段获取所有值.

现在我想在FetchXML中执行此操作,我尝试or在它们之间放置两个带过滤器的条件,一个用于值,另一个包含空值,如下所示:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
   <entity name="incident"> 
      ...
      ...
      <filter type="and">
         <filter type="and">
           <condition attribute="createdon" operator="on-or-after" value="@StartDate" /> 
           <condition attribute="createdon" operator="on-or-before" value="@EndDate" /> 
         </filter>
         <filter type="or">
           <condition attribute="new_gen_comp_type" operator="in" value="@new_gen_comp_type" /> 
           <condition attribute="new_gen_comp_type" operator="null" /> 
         </filter>
      </filter>

      ...
      ...
  </entity>
</fetch>
Run Code Online (Sandbox Code Playgroud)

只有当用户选择参数的所有值时,这才能正常工作@new_gen_comp_type,但问题是如果用户只选择特定值,它也会包含空值,这是错误的.

那么,如果用户选择select allSQL中的参数值,有没有办法让这些条件成为可选项?

Dar*_*ryl 4

由于您是在 SSRS 中执行此操作,因此您无法选择更改 Fetch XML,而这正是您真正需要做的。(如果用户选择“ALL”,则不包含 的约束new_gen_comp_type

我能想到的唯一选择有点愚蠢,但它应该可行。在事件上创建一个new_all默认为“ALL”的新属性,然后运行更新语句将所有现有事件填充为“ALL”。然后将 FetchXml 过滤器更改为:

<filter type="or">
    <condition attribute="new_gen_comp_type" operator="eq" value="@new_gen_comp_type" /> 
    <condition attribute="new_all" operator="eq" value="@new_gen_comp_type" /> 
</filter>
Run Code Online (Sandbox Code Playgroud)

如果用户选择“ALL”,则第二个语句将为 true,并且将返回所有内容。如果用户选择除 ALL 之外的其他内容,则第二个语句将始终为 false,并且第一个语句将仅返回匹配的内容。

请注意,该属性operator="in"不适用于多个值。您需要为每个值创建一个值子标签......

来自 XSD:

属性“value”用于与单个值进行比较的所有运算符(例如,eq)。元素“value”用于与多个值进行比较的运算符(例如,in)。某些运算符既不需要属性“value”,也不需要元素“value”(例如 null)。