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