I have some SQL reports that has very slow performance, so we converted all of them into FetchXML, but all the SQL reports has all the conditions optional, something like this:
SELECT
...
FROM ...
WHERE (@operator = 'All' OR Operator = @operator)
AND (@new_gen_comp_name = 'All' OR new_gen_comp_name = @new_gen_comp_name)
...
In the parameters values, there is a value All
if the user select this value, the condition will be ignored and therefore it will get all the values from that field.
Now I want to do that in FetchXML, I tried to put two conditions with filter or
between them, one for the value and another to include null values like this:
<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>
This worked fine only if the user select all the values for the parameter @new_gen_comp_type
, but the problem is if the user select only specific values, it will include the null values too, and that is wrong.
So, is there any way to make these conditions optional in case if the user select select all
for the values of the parameter like in SQL?