" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode \n"+
" Set_KanBanSettle\n"+
" AS A LEFT JOIN Set_material AS b ON A.MaterialCode = b.CustomerPartCode\n"+
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle WHERE VERSION < '{0}' GROUP BY kanban, MaterialCode ) temp1\n"+
" INNER JOIN ( SELECT SUM ( WMSDeliveryQty ) Qty, KanBan, MaterialCode FROM Set_WMSKanBanSettle WHERE WMSActualGoodsDate < '{2}' GROUP BY KanBan, MaterialCode ) temp2 ON temp1.Kanban = temp2.KanBan \n"+
" AND temp1.MaterialCode = temp2.KanBan \n"+
" ) C ON A.Kanban = C.Kanban \n"+
" AND A.MaterialCode = C.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE VERSION = '{0}' GROUP BY materialcode ) d ON A.MaterialCode = d.MaterialCode \n"+
" WHERE\n"+
" a.VERSION= '{0}' {1} \n"+
" A.VERSION = '{0}' {1}\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n"+
" FROM Set_PriceList WHERE VERSION = ( SELECT MAX ( VERSION ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n"+