REPORTFORM;SA13.frf
TITLE;วิเคราะห์ขาย สรุปยอดขายตาม เขตการขาย+วันที่
SQL;SELECT
SQL;ARCARD.AREA,
SQL;AREA.ADESC,
SQL;INVCARD.DATEDOC, 
SQL;INVCARD.ID,
SQL;INVMST.XDESC,
SQL;INVMST.UNIT,
SQL;SUM(INVCARD.SALEPURQTY) AS SALEPURQTY,
SQL;SUM(INVCARD.SALEPURAMT) AS SALEPURAMT
SQL;FROM INVCARD 
SQL;LEFT JOIN ARCARD ON INVCARD.DOCNO = ARCARD.DOCNO 
SQL;LEFT JOIN INVMST ON INVCARD.ID = INVMST.ID
SQL;LEFT JOIN AREA ON ARCARD.AREA = AREA.ADESC
SQL;WHERE (LEFT(INVCARD.DOCNO,2) = "IV" OR LEFT(INVCARD.DOCNO,2) = "RI")
SQL;GROUP BY  ARCARD.AREA,AREA.ADESC,INVCARD.ID
SQL;ORDER BY ARCARD.AREA,INVCARD.DATEDOC,INVCARD.ID
CONDITION;ตั้งแต่วันที่~INVCARD.DATEDOC~Date~2~SELECT DATEDOC FROM INVCARD~
CONDITION;ตั้งแต่เขตการขาย~ARCARD.AREA~Chr~2~SELECT AID FROM AREA~AREA
EXCELSQL;SELECT
EXCELSQL;INVCARD.DATEDOC AS "วันที่เอกสาร", 
EXCELSQL;INVCARD.ACCID AS "รหัสลูกค้า",
EXCELSQL;ARMST.XCOMP AS "รายละเอียดลูกค้า",
EXCELSQL;INVCARD.ID AS "รหัสสินค้า",
EXCELSQL;INVMST.XDESC AS "รายละเอียดสินค้า",
EXCELSQL;INVMST.UNIT AS "หน่วยนับ",
EXCELSQL;ARCARD.AREA AS "เขตการขาย",
EXCELSQL;AREA.ADESC AS "ชื่อเขตการขาย",
EXCELSQL;SUM(INVCARD.SALEPURQTY) AS SALEPURQTY,
EXCELSQL;SUM(INVCARD.SALEPURAMT) AS SALEPURAMT
EXCELSQL;FROM INVCARD 
EXCELSQL;LEFT JOIN ARMST ON INVCARD.ACCID = ARMST.ACCID
EXCELSQL;LEFT JOIN ARCARD ON INVCARD.DOCNO = ARCARD.DOCNO 
EXCELSQL;LEFT JOIN INVMST ON INVCARD.ID = INVMST.ID
EXCELSQL;LEFT JOIN AREA ON ARCARD.AREA = AREA.ADESC
EXCELSQL;WHERE (LEFT(INVCARD.DOCNO,2) = "IV" OR LEFT(INVCARD.DOCNO,2) = "RI")
EXCELSQL;GROUP BY INVCARD.ACCID,ARMST.XCOMP,INVCARD.ID,INVMST.XDESC,INVMST.UNIT,
EXCELSQL;ARCARD.AREA,AREA.ADESC
EXCELSQL;ORDER BY ARCARD.AREA,INVCARD.DATEDOC, INVCARD.DOCNO,INVCARD.LINE
