title: create relationships in neo4j cypher using case statement
body: <p>I have a JSON in the next form:</p>
  
  <pre><code>{ "conditions": [ { "id": "123", "type": "a", entities: ["529", "454"] },
                    { "id": "124", "type": "b", entities: ["530", "455"] }
    ]
  } 
  </code></pre>
  
  <p>I want to create relation ship between the Condition node with node A Entities or node B entities based on type attribute which can be A/B i Assuming that these entities already exists in neo4j.</p>
  
  <p>I am trying something like the below cypher but that doesn't work. </p>
  
  <pre><code>WITH {json} as data
  UNWIND data.conditions as condition 
  MATCH (c:Condition { conditionId: condition.id})
  CASE c.type 
      WHEN 'a' THEN FOREACH (sid IN condition.entities | 
          MERGE (s:NodeA {nr_serverId:sid}) MERGE (s)-[:ATTACHED_TO]-&gt;(c)
      )
      WHEN 'b' THEN FOREACH (aid IN condition.entities | 
         MERGE (a:NodeB {nr_appId: aid}) MERGE (a)-[:ATTACHED_TO]-&gt;(c)
      )
  END;
  </code></pre>
  
  <p>Can anyone please help me with the correct way of doing this? Thank you.</p>