Counting records in a child table and storing the value in a field of a master table
I have 2 tables T1 (master) and T2 (child) with the following fields:
T1(COD, TOTAL, T2) - here T2 is the reference field for table T2
T2(QTD, T1) - here T1 is the reference field for table T1
On a Button in table T1 I have code counting, for the current record, the number of records in T2 with COD value of the current record in T1 and storing the result in TOTAL.
This works fine with the following code:
let x := COD;
let y := (select T2 where T1.COD = x);
TOTAL := cnt(y);
But it does not work if I write:
let y := (select T2 where T1.COD = COD);
TOTAL := cnt(y);
I get the message: "Field not found COD".
I thought that COD should be referencing the COD var in the current record of T1, but it seems it is not.
What am i missing?
2 replies
-
In a "select" statement, the context for the evaluation of the filtering condition is, in turn, each record of the table named after "select". You are calling table "T2", and table "T2" does not contain a field named "COD", hence the error message.
Now, since there is a reference available, a "select" is not needed at all: the number of records of "T2" linked to each record of "T1" is simply: cnt(T2).
-
Thank you very much for your explanation.
You were quite clear.
Content aside
- 2 yrs agoLast active
- 2Replies
- 208Views