0

I'm having trouble getting this query to work:

MATCH (pb:PRO{code: $pb, letter:$L})-[customerof:CUSTOMER_OF]->(c:CUSTOMER)-[:HAS_CONTRACT]->(con:CONTRACT)-[:HAS_POSITION]->(pos:POSITION)-[:HAS_PRODUCTS]->(prod:PRODUCT) WHERE
    (
        'ALL' in $filter
        or
        (
            'FIRST' in $filter
            and (prod.famprod in ['AC','DT'] and not prod.contractType in ['95|FUNDS']))
        or
        (
            'SECOND' in $filter
            and not prod.famprod in ['AC'] OR(prod.famprod IN ['AC','DT'] and prod.contractType  in ['95|FUNDS'])
        )
    )
    and
    (
        $customerType='ALL'
        or
        (
            $customerType='SINGLE'
            and
            customerof.flagSingle='1'
        )
        or
        (
            $customerType='NOTSINGLE'
            and
            customerof.flagSingle='0'
        )
    )

The problem arises when I run 'FIRST' OR 'SECOND': running 'FIRST' the query, despite the "not" returns also prod.contractType in ['95|FUNDS']; running 'SECOND' the return is right.

I'm not so good with neo4j (first experience) and i can't solve the problem: i tried almost 20 different combinations but it doesn't work.

It looks like they are mirrored: when i try to modify 'FIRST', sometimes it changes the return of 'SECOND'.

'ALL' works fine.

Can you help me to get the right return?

Thanks

User992
  • 1
  • 1
  • Why do you use `NOT IN` for `prod.contractType` since you check the value against a collection of a single item ('95|FUNDS')? `prod.contractType <> '95|FUNDS'` would be easier to understand. Also, `prod.famprod ['AC','DT']` is not correct Cypher. Are you missing an `IN` there? – fbiville Jul 29 '21 at 07:52
  • Sorry, i missed the IN due to an error while copying the text. – User992 Jul 29 '21 at 08:37
  • Anyone can help me? How can i solve this problem? Should i try a CASE/WHEN? – User992 Aug 18 '21 at 14:22
  • The best way to proceed is to test the WHERE clause piece by piece. – fbiville Aug 19 '21 at 09:01

0 Answers0