; WITH THPOJUAL AS (SELECT * FROM THPOJUAL2008 AS A UNION ALL SELECT * FROM THPOJUAL2009 AS A UNION ALL SELECT * FROM THPOJUAL2010 AS A ) , TDPOJUAL AS (SELECT * FROM TDPOJUAL2008 AS B UNION ALL SELECT * FROM TDPOJUAL2009 AS B UNION ALL SELECT * FROM TDPOJUAL2010 AS B )
SELECT SUM( (B.Harga_Net / B.Qty_PO) * (B.Qty_SJ - B.Qty_Fkt) ) AS NilaiPO FROM THPOJUAL AS A LEFT JOIN TDPOJUAL AS B ON A.Nomor_OA = B.Nomor_OA WHERE A.CustCode = 'ADJ04' AND B.Qty_SJ > B.Qty_Fkt
|