Hi
I have below query . In C1 there are more than 1 record but below Cursor is showing only 1 record
Declare CURSOR C1 FOR Select T0."CardCode",T0."CardName",T0."U_AREA",T0."U_ROUTE",
T0."U_Rider_1",T0."U_Rider_2",T0."U_Rider_3",T0."U_Rider_4"
from OCRD T0
inner join OCRG T1 on T0."GroupCode" = T1."GroupCode"
;
for cur_row as C1 Do
SELECT cur_row."CardCode",cur_row."CardName",cur_row."U_AREA",cur_row."U_ROUTE",
T2."DocDate",T2."DocNum",
(Select Sum("LineTotal") from INV1 where "DocEntry" = T2."DocEntry") As "Inv Total" ,'' As "Rider",
'0' As "Exp Total"
FROM OCRD T0
left join OINV T2 on T2."CardCode" = T0."CardCode"
where T2."DocDate" >= (:FromDate) and T2."DocDate" <= (:ToDate)
and T0."CardCode" = cur_row."CardCode"
end for;
Thanks
Amira BedhiafiPosted Apr 8, 2025, 10:32 AM
Your cursor C1 iterates over all matching OCRD records, but inside the loop, you're rejoining OCRD again with OINV, and filtering again by the same CardCode, so the loop essentially becomes redundant because you're fetching data from OCRD again instead of using cur_row.
You should use only the data from the cursor row inside the loop, and not re-query OCRD so instead, just join OINV with cur_row.CardCode.