Alias written in foreach cant be called in CALL apoc.create.relationship()

Load csv with headers from "file:///newtask.csv" as row
FOREACH(ignoreMe IN CASE WHEN row.A IS NOT NULL THEN [1] ELSE END | MERGE(p1:person{firstName:row.A,age:row.E}))
FOREACH(ignoreMe IN CASE WHEN row.E IS NOT NULL THEN [1] ELSE END | MERGE(p2:person{firstName:row.B,age:row.E}))
WITH p1, p2, row
CALL apoc.create.relationship(p1, row.C,{number:row.D}, p2) YIELD rel
RETURN rel

Queries are based on this

Looks like variables p1 and p2 defined one the forEach loop are not available outside the loop. This seems reasonable, as you are iterating over a list and exchange iteration would produce a new p1 and p2.

For your case, you can replace the forEach clause with a ‘with row where row.A is not null and row.E is not null’ statement, followed by your two merge statements and apoc call.

Btw, the code in the error message is not the same as the code you pasted. My response is to address the errored code.

thank you for your response . I"m trying to get this o/p

with query
load csv with headers from "file:///newtask.csv" as row
WITH row WHERE NOT row.E IS null
WITH row WHERE NOT row.A IS null
MERGE(p1:person{firstName:row.A,age:row.E})
MERGE(p2:person{firstName:row.B})
WITH p1, p2, row
CALL apoc.create.relationship(p1, row.C,{number:row.D}, p2) YIELD rel
RETURN rel


i got o/p like this still one node "Gary" is missing.
how can i make dynamic relationship with foreach loop. Thanks in advance.