Hi,
I don't understand why the result of the CASE is the ELSE value instead of "Eekels".
What I'm doing wrong?
MATCH (equipmentData:Equipment)
WITH equipmentData,
CASE equipmentData.objectId
// WHEN equipmentData.objectId IS NULL THEN "Third Party"
// WHEN equipmentData.objectId IS NOT NULL THEN "Eekels"
WHEN NULL = TRUE THEN "Third Party"
WHEN NULL = FALSE THEN "Eekels"
ELSE ""
END AS responsible
SET equipmentData.responsible = responsible
RETURN equipmentData.responsible, equipmentData.objectId
You can not compare a value to NULL with the equality operator. The value of the comparison is always null, so you hit the ELSE statement. You have to use 'IS NULL' and "IS NOT NULL'.
MATCH (area:Area)
WITH area
MATCH (equipmentData:Equipment)
WITH area, equipmentData
CALL apoc.when(
equipmentData.EqTAG = area.equipmentFrom,
'RETURN "Eekels" as result',
'RETURN "Third Party" as result',
{equipmentData:equipmentData}
) YIELD value
SET equipmentData.responsible = value.result;
Batch 2
//Separated clauses. It doesn't work together
MATCH (equipmentData:Equipment)
RETURN equipmentData.responsible, equipmentData.EqTAG
MATCH (area:Area)
MATCH (equipmentData:Equipment)
WITH area, equipmentData,
CASE WHEN equipmentData.EqTAG = area.equipmentFrom THEN "Eekels" ELSE "Third Party" END as value
SET equipmentData.responsible = value;
The reason the following did not set equipmentData.objectId = NULL is that the query ends when equipmentData.EqTAG <> area.equipmentFrom, so equipmentData.objectId never gets altered for these Equipment nodes.
MATCH (area:Area)
WITH area
MATCH (equipmentData:Equipment)
WHERE equipmentData.EqTAG = area.equipmentFrom
SET equipmentData.objectId = area.objectId;
If you want to set it to null when the equality is false (setting to null removes the property), you can do the following:
MATCH (area:Area)
MATCH (equipmentData:Equipment)
WITH area, equipmentData,
CASE WHEN equipmentData.EqTAG = area.equipmentFrom THEN area.objectId ELSE null END as value
SET equipmentData.objectId = value
Thanks for your input. Learnt again the behavior of Neo4j.
I solved my case in another way.
I check the relation between area and equipmentData. When the relation exists I set the property.
MATCH (area:Area)-[:CONSIST_OF_E]->(equipmentData:Equipment)
SET equipmentData.responsible = "Eekels";
Hereafter I check which property IS NULL.
When NULL I set the property with another value.
MATCH (equipmentData:Equipment)
WHERE equipmentData.responsible IS NULL
SET equipmentData.responsible = "Third Party";