Fatal Error when compiling a code

P

I have a database with registered clients. Among all, I try to get the total payments, filtered by date. That is, for example, how much I got between September 1 and September 30.
In MySQL, I do it with a code "WHEN DATE BETWEEN INIT_DATE AND END_DATE".
I made this code in button, but it freezes the app:

TOTAL := sum(PAYMENTS[PAYMENTS[range(INIT_DATE,END_DATE)].DATE].QUANTITY)

PAYMENTS: TABLE.
TOTAL: NUMBER FIELD.
INT_DATE: DATE FIELD.
END_DATE: DATE FIELD.
DATE: DATE FIELD.
QUANTITY: NUMER FIELD.

I hope you can help me.
Regards.

Reply