lnYear = yearfromsomewhere SELECT DISTINCT dl.date, ; dl.code, ; dl.category, ; SUM(IIF(ca.category="H",1,0)) AS CntCatH, ; SUM(IIF(ca.category="B",1,0)) AS CntCatB, ; FROM dlyatten dl LEFT JOIN (alias11) ca ON dl.date = ca.date ; WHERE YEAR(dl.date) = lnYear ; INTO CURSOR temp(to Khalid)