Код: Выделить всё
table struct SellsAggr
(
cAn1 : comp,
cAn2 : comp,
cAn3 : comp,
SumUslAggr : double
)
with index
(
SellsAggr01 = cAn1 + cAn2 + cAn3
);
................................................................................................
MTClear(#SellsAggr, mfNormal);
dFrom := dBegDate;
dTo := dEndDate;
cAttrNam_NaprIsp := piExtAttr.AttrID(coKatZak, cAttrNam_NaprIsp_Name);
cAttrNam_KontrVid := piExtAttr.AttrID(coKatOrg, cAttrNam_KontrVid_Name);
StatPl := 1;
if cAttrNam_NaprIsp <> 0 and cAttrNam_KontrVid <> 0
{
SQL
SELECT KatOrg.NRec as cAn1,
NaprIsp.NaprIsp_vComp as cAn2,
KontrVid.KontrVid_vComp as cAn3,
SUM(ALL SpZakaz.SumUsl) as SumUslAggr
FROM
PutLst
INNER JOIN KatZak ON KATZAK.CPUTLST = PUTLST.NREC
INNER JOIN KATORG ON KATZAK.CORG = KATORG.NREC
LEFT OUTER JOIN SPZAKAZ ON KATZAK.NREC = SPZAKAZ.CKATZAK
LEFT OUTER JOIN
(SELECT ATTRVAL_NaprIsp.cRec as NaprIsp_cRec, ATTRVAL_NaprIsp.vComp as NaprIsp_vComp
FROM ATTRVAL AS ATTRVAL_NaprIsp
WHERE (ATTRVAL_NaprIsp.CATTRNAM = :cAttrNam_NaprIsp )
) AS NaprIsp ON KatZak.NRec = NaprIsp.NaprIsp_cRec
LEFT OUTER JOIN
(SELECT ATTRVAL_KontrVid.cRec as KontrVid_cRec, ATTRVAL_KontrVid.vComp as KontrVid_vComp
FROM ATTRVAL AS ATTRVAL_KontrVid
WHERE (ATTRVAL_KontrVid.CATTRNAM = :cAttrNam_KontrVid )
) AS KontrVid ON KatOrg.NREC = KontrVid.KontrVid_cRec
WHERE (PUTLST.DATOBR >= :dFrom )
AND (PUTLST.DATOBR <= :dTo )
AND (PUTLST.STATPL = :StatPl )
GROUP BY KatOrg.NRec,
NaprIsp.NaprIsp_vComp,
KontrVid.KontrVid_vComp
INTO SellsAggr byName
;