**** First Change see SUM() whole_sql ="SELECT SiMain.*, SisUb.ICode, SUM(SisUb.qntymaj) AS QntyMaj, SUM(SisUb.qntymin) AS QntyMin, SisUb.RateMaj, SisUb.RateMin, "+; "PCode.PName, Icode.full_desc, Icode.unit "+; "FROM SiMain "+; "RIGHT JOIN SisUb ON SiMain.SiNo == SisUb.SiNo "+; "LEFT JOIN PCode ON SiMain.PCode == PCode.PCode "+; "LEFT JOIN Icode ON sisub.Icode == Icode.Icode "+; "WHERE BETWEEN(Simain.Invdate, mdt1, mdt2)" msalesman = UPPER(This.Parent.msalesman.Value) mpcode = This.Parent.mpcode.Value IF This.Parent.Check1.Value = 1 && Filter only by some SalesMan whole_sql = whole_sql + " .AND. UPPER(Simain.Salesman) == '"+msalesman+"'" ENDIF IF This.Parent.Check2.Value = 1 && Filter only by some PCOde whole_sql = whole_sql + " .AND. Simain.PCode == '"+This.Parent.mpcode.Value+"'" ENDIF ** Second Change added GROUP BY clause whole_sql = whole_sql +" GROUP BY SiMain.PCode, SisUb.ICode ORDER BY SiMain.PCode INTO CURSOR tempsale"Pls check if it works, because I can't test it.