I need to match using 4 different logic in a sequence each time a match is not found. How can I accomplish this?

18 views
Skip to first unread message

Shanthi Viswanathan

unread,
Nov 25, 2020, 6:10:18 AM11/25/20
to Neo4j
I have 2 nodes employees and contractors. I get a name either with id or not. If I get the id then match on id and if not match on name. First match is against employees followed by contractor.  If I do not get a match then do a fuzy match with the name first for employee node and then contractor node.

WITH row WHERE row.CREATED_BY <> 'None' 
  CALL apoc.when(row.CREATED_BY_NTID IS NOT NULL, 
        "MATCH (p:Employee {name: row.CREATED_BY}) WHERE p.account ENDS WITH row.CREATED_BY_NTID return p", 
        "MATCH (p:Employee {name: row.CREATED_BY}) return p", {row:row}) yield value 
With row, value.p as p 
   IF value.p IS null 
   CALL apoc.when(row.CREATED_BY_NTID IS NOT NULL, 
         "MATCH (p:Contractor {name: row.CREATED_BY}) WHERE p.account ENDS WITH row.CREATED_BY_NTID return p", 
 "MATCH (p:Contractor {name: row.CREATED_BY}) return p", {row:row}) yield value 
With row, value.p as p 
 IF value.p IS null match (p:Employee) where p.name starts with 'XXXXXXX' return p  
Reply all
Reply to author
Forward
0 new messages