REPORTFORM;AP8.frf
TITLE;ยอดหนี้คงเหลือและเช็คล่วงหน้าเจ้าหนี้
SQL;DROP TABLE IF EXISTS _XAPCHK&
SQL;
SQL;CREATE TABLE _XAPCHK
SQL;SELECT APMST.ACCID, APMST.XCOMP, SUM(APCARD.REPBAL) AS DB, 00000000.00 AS PCHK
SQL;FROM APCARD INNER JOIN APMST ON APCARD.ACCID = APMST.ACCID
SQL;WHERE APCARD.ACCID >= :M11 AND APCARD.ACCID <= :M12
SQL;AND APCARD.DATEDOC < :M21
SQL;GROUP BY APMST.ACCID, APMST.XCOMP
SQL;ORDER BY APCARD.ACCID&
SQL;
SQL;DROP TABLE IF EXISTS _XAPCHK2&
SQL;
SQL;CREATE TABLE _XAPCHK2
SQL;SELECT BKTR.APACCID AS ACCID, SUM(BKTR.AMT_OUT) AS PCHK
SQL;FROM BKTR 
SQL;WHERE BKTR.TRTYPE = "AP" 
SQL;AND LEFT(BKTR.PAYTYPE,2) = "02"
SQL;AND BKTR.CLRCHK = 0
SQL;AND BKTR.APACCID >= :M11 AND BKTR.APACCID <= :M12 
SQL;AND BKTR.DATECHK < :M21
SQL;GROUP BY BKTR.APACCID&
SQL;
SQL;UPDATE _XAPCHK INNER JOIN _XAPCHK2 ON _XAPCHK.ACCID = _XAPCHK2.ACCID
SQL;SET _XAPCHK.PCHK = _XAPCHK2.PCHK&
SQL;
SQL;DROP TABLE IF EXISTS _XAPCHK2&
SQL;
SQL;SELECT * FROM _XAPCHK 
CONDITION;ตั้งแต่รหัสเจ้าหนี้~APCARD.ACCID~Chr~2~SELECT ACCID FROM APMST~AP
CONDITION;สิ้นสุด ณ วันที่~APCARD.DATEDOC~Date~1~<=~
