title: In Neo4j Cypher, How to iterate using LOAD CSV, UNWIND/FOREACH and WITH clauses?
body: <p>In Neo4j, using Cypher, I want to run the below query for numbers 1 through 14 (i.e., <code>quantity1</code> to <code>quantity14</code>):</p>
  <pre><code>LOAD CSV WITH HEADERS FROM '&lt;path&gt;' AS row 
  WITH row WHERE row.quantity1 IS NOT NULL
  MATCH (m:main {main_id: row.main}) 
  MERGE (q:quantity {quantity : row.quantity1}) 
  MERGE (m)-[:main_has_quantity]-&gt;(q);
  </code></pre>
  <p>What the command does: The command reads a CSV, creates the quantity node (if it is not null and if it doesn't already exist) and then creates a relationship between the quantity node and it's corresponding main node. I want to do this for columns <code>quantity1</code> through <code>quantity14</code> in the CSV.</p>
  <p>I tried to use <code>UNWIND</code> and <code>FOREACH</code> but both commands throw errors:</p>
  <pre><code>LOAD CSV WITH HEADERS FROM '&lt;path&gt;' AS row 
  UNWIND range(1,14) as i
  WITH row WHERE row.quantity+toString(i) IS NOT NULL 
  MATCH (m:main {main_id: row.main}) 
  MERGE (q:quantity {quantity : row.quantity+toString(i)}) 
  MERGE (m)-[:main_has_quantity]-&gt;(q);
  </code></pre>
  <p>I got the error:</p>
  <blockquote>
  <p>Variable <code>i</code> not defined (line 5, column 37 (offset: 246)) &quot;MERGE
  (q:quantity {quantity : row.quantity+toString(i)})&quot;</p>
  </blockquote>
  <p>I used <code>FOREACH</code> in place of <code>UNWIND</code> but that did not work because I cannot use <code>WITH</code> clause inside <code>FOREACH</code>.</p>
  <p>How best to achieve the result I am looking for?</p>
  <p>P.S. I am using the Neo4j community version.</p>