Kural
Kural

Reputation: 212

How to commonly use not operator for two queries in ODATAV4?

Currently, my query string is like below,

http://localhost:49442/Orders/?$count=true&$filter=not%20(Freight%20eq%202.3)%20and%20(startswith(tolower(CustomerID),%27b%27))&$skip=0&$top=12

But here not-operator only worked to filter the Freight column. But I want to commonly us this not-operator to filter Freight and CustomerID.

Upvotes: 2

Views: 454

Answers (1)

Chris Schaller
Chris Schaller

Reputation: 16767

Its hard to identify your intended expression as it is half-way between two:

  1. If you want to exclude only the rows where both of the following are true at the same time:

    • Freight eq 2.3
    • Customer starts with 'b'

    Then you can do this by rearranging the brackets, the following is the same as saying:
    "Exclude orders where the Customer starts with b, but only if the freight is 2.3"

    http://localhost:49442/Orders/?$count=true&$filter=not(Freight eq 2.3 and startswith(tolower(CustomerID),'b'))&$skip=0&$top=12
    
  2. If instead you want to exclude all orders that have customers that start with 'b' AND also exclude all other orders where the freight is 2.3 then you must specify not twice in your query

    • This is the same as: "Exclude orders where the Customer starts with b, or if the freight is 2.3"

      http://localhost:49442/Orders/?$count=true&$filter=not(Freight eq 2.3) and not(startswith(tolower(CustomerID),'b'))&$skip=0&$top=12
      

Upvotes: 0

Related Questions