<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Filter null values in date field in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaa-p/12524358#M4694563</link>
    <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;fabian.zimmermann&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Have you tried this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET /EntitySet?$filter=(DateProperty+eq+null)
GET /EntitySet?$filter=not(DateProperty+eq+null)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or, how about adding an entity as a projection of your original entity with a select statement on your service definition, like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;service GenericService {
  entity EntitySet as a projection on MyDataModelEntity;

  entity DatelessEntitySet as select from EntitySet {*}
	where DateProperty is null;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This way you would be simplifying your OData requests at the UI level while avoiding to have excessive/unecessary filters in the first place.&lt;/P&gt;&lt;P&gt;Then you would be able to get it directly without any filter expressions.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET /GenericService/DatelessEntitySet&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please read more here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sap.com/2019/03/11/sap-cloud-platform-backend-service-tutorial-9-cds-how-to-use-select-statement/" target="test_blank"&gt;https://blogs.sap.com/2019/03/11/sap-cloud-platform-backend-service-tutorial-9-cds-how-to-use-select-statement/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;Ivan&lt;/P&gt;</description>
    <pubDate>Wed, 15 Dec 2021 16:01:40 GMT</pubDate>
    <dc:creator>Ivan-Mirisola</dc:creator>
    <dc:date>2021-12-15T16:01:40Z</dc:date>
    <item>
      <title>Filter null values in date field</title>
      <link>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaq-p/12524357</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;
  &lt;P&gt;I am running a capire odata instance on SAP BTP and want to filter for entities that "do not have a date", i.e. where the date field is null.&lt;/P&gt;
  &lt;P&gt;This request gives me an empty result&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Request:&lt;/STRONG&gt; GET /EntitySet?$filter=DateProperty eq null&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt; {"@odata.context":"$metadata#EntitySet","@odata.count":0,"value":[]}&lt;/P&gt;
  &lt;P&gt;The opposite request includes all records, including the ones that have null for that property&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Request:&lt;/STRONG&gt; GET /EntitySet?$filter=DateProperty ne null&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt; {"@odata.context":"$metadata#EntitySet","@odata.count":5093,"value":[{...,DateProperty":null,...},...]&lt;/P&gt;
  &lt;P&gt;When uppercasing null (NULL) it says that a property NULL is not available - which tells me that the system does recognize null as a valid value for the date field...&lt;/P&gt;
  &lt;P&gt;Therefore I am a little bit lost.&lt;/P&gt;
  &lt;P&gt;Could you give me some guidance?&lt;/P&gt;
  &lt;P&gt;Thank you.&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Fabian&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 09:26:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaq-p/12524357</guid>
      <dc:creator>fabian_zimmermann</dc:creator>
      <dc:date>2021-12-15T09:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filter null values in date field</title>
      <link>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaa-p/12524358#M4694563</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;fabian.zimmermann&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Have you tried this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET /EntitySet?$filter=(DateProperty+eq+null)
GET /EntitySet?$filter=not(DateProperty+eq+null)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or, how about adding an entity as a projection of your original entity with a select statement on your service definition, like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;service GenericService {
  entity EntitySet as a projection on MyDataModelEntity;

  entity DatelessEntitySet as select from EntitySet {*}
	where DateProperty is null;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This way you would be simplifying your OData requests at the UI level while avoiding to have excessive/unecessary filters in the first place.&lt;/P&gt;&lt;P&gt;Then you would be able to get it directly without any filter expressions.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET /GenericService/DatelessEntitySet&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please read more here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sap.com/2019/03/11/sap-cloud-platform-backend-service-tutorial-9-cds-how-to-use-select-statement/" target="test_blank"&gt;https://blogs.sap.com/2019/03/11/sap-cloud-platform-backend-service-tutorial-9-cds-how-to-use-select-statement/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;BR /&gt;Ivan&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 16:01:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaa-p/12524358#M4694563</guid>
      <dc:creator>Ivan-Mirisola</dc:creator>
      <dc:date>2021-12-15T16:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Filter null values in date field</title>
      <link>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaa-p/12524359#M4694564</link>
      <description>&lt;P&gt;Hello Ivan,&lt;/P&gt;&lt;P&gt;thank you for your answer!&lt;/P&gt;&lt;P&gt;The result with parantheses is identical (i.e. same problem). The "not" does not even work. It is interpreted as a property by the Capire odata service.&lt;/P&gt;&lt;P&gt;The suggestion with the entity projection would not work in my case, I think. My application behaves like a pivot table. The user selects the fields to use in his table (or chart), sets the filters and so on. I would have to make a projection for every field in my data model (and then the user would probably not be able to combine that field with others).&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Fabian&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 16:23:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/filter-null-values-in-date-field/qaa-p/12524359#M4694564</guid>
      <dc:creator>fabian_zimmermann</dc:creator>
      <dc:date>2021-12-15T16:23:24Z</dc:date>
    </item>
  </channel>
</rss>

