>CREATE TABLE DooSumi (NadvDoo N(14,2), SumaDoo N(14,2), Mes N(2), God N(4), Egn C(10)) >CREATE TABLE AddSum (Bruto N(14,2), Mes N(2), God N(4), Egn C(10)) >INSERT INTO DooSumi (NadvDoo, SumaDoo, Mes, God, Egn) VALUES (100, 50, 2, 2003, "1111111111") >INSERT INTO DooSumi (NadvDoo, SumaDoo, Mes, God, Egn) VALUES (120, 50, 2, 2003, "1111111111") >INSERT INTO DooSumi (NadvDoo, SumaDoo, Mes, God, Egn) VALUES (120, 50, 2, 2003, "1111111111") > >INSERT INTO AddSum (Bruto, Mes, God, Egn) VALUES (100, 2, 2003, "1111111111") > >SELECT SUM(NadvDoo + SumaDoo) + NVL(AddSum.Bruto,0) AS All_Nadv; > FROM DooSumi; > LEFT JOIN AddSum ON DooSumi.Egn+STR(2003,4)+STR(2,2) == AddSum.Egn + STR(AddSum.God,4)+STR(AddSum.Mes,2); > WHERE DooSumi.Egn == "1111111111" .AND. DooSumi.Mes == 2 .AND. DooSumi.God == 2003; > GROUP BY DooSumi.Egn, DooSumi.Mes, DooSumi.God; >INTO CURSOR TempDoo>
NVL(AddSum.Bruto,0) AS All_Nadv
is not aggregated, even though it is added to an aggregated field. The code worked with AddSum.Bruto
added to the GROUP BY clause. You don't need to include DooSumi.Egn, DooSumi.Mes, DooSumi.God
in the GROUP BY clause since these fields don't appear in the SELECT clause. In any case, grouping by them is not meaningful since you can't see what the values were.