" (Price-InvoicePrice) as InvoiceDiffPrice, --单价差异\n"+
" (Price-InvoicePrice) as InvoiceDiffPrice, --单价差异\n"+
" ISNULL( Price * ReceiptQty-InvoiceMoney, 0 ) AS SumDiffMoney --总金额差异\n"+
" ISNULL( Price * ReceiptQty-InvoiceMoney, 0 ) AS SumDiffMoney --总金额差异\n"+
"FROM\n"+
"FROM\n"+
" (\n"+
" (\n"+
" SELECT\n"+
" SELECT\n"+
" c.Period as WMSDeliveryDate,--交货日期\n"+
" c.Period as WMSDeliveryDate,--交货日期\n"+
" c.DeliveryOrderNo,--交货单号\n"+
" c.DeliveryOrderNo,--交货单号\n"+
" c.SpareDate as OrderDate,--订单日期\n"+
" c.SpareDate as OrderDate,--订单日期\n"+
" a.PurchaseOrderNo,--采购订单号\n"+
" a.PurchaseOrderNo,--采购订单号\n"+
" b.MaterialCode as SAPCode,--SAP编码,即厂内物料号\n"+
" b.MaterialCode as SAPCode,--SAP编码,即厂内物料号\n"+
" a.MaterialCode,--物料代码\n"+
" a.MaterialCode,--物料代码\n"+
" b.MaterialDesc,--物料描述\n"+
" b.MaterialDesc,--物料描述\n"+
" a.PurchaseOrderNoText,--采购订单文本\n"+
" a.PurchaseOrderNoText,--采购订单文本\n"+
" c.ReceiptQty,-- 发货数量\n"+
" c.ReceiptQty,-- 发货数量\n"+
" d.Amt as InvoicedQty,--开票数量\n"+
" d.Amt as InvoicedQty,--开票数量\n"+
" (c.ReceiptQty-d.Amt) as SettleInvoiceDiffQty,--发货与开票差异\n"+
" (c.ReceiptQty-d.Amt) as SettleInvoiceDiffQty,--发货与开票差异\n"+
" d.InvoicePrice,--开票单价\n"+
" d.InvoicePrice,--开票单价\n"+
" (a.ReceiptQty * d.InvoicePrice) as InvoiceMoney --开票金额\n"+
" (a.ReceiptQty * d.InvoicePrice) as InvoiceMoney --开票金额\n"+
" \n"+
"\n"+
" FROM\n"+
" FROM\n"+
" Set_SparePart AS a\n"+
" Set_SparePart AS a\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_WMSSparePart c ON a.PurchaseOrderNo= c.WMSDeliveryNote \n"+
" LEFT JOIN Set_WMSSparePart c ON a.PurchaseOrderNo= c.PurchaseOrderNo \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode,Amt FROM set_invoice WHERE version = '202109' GROUP BY materialcode,Amt ) d ON a.MaterialCode= d.MaterialCode \n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode,Amt FROM set_invoice WHERE version = '202109' GROUP BY materialcode,Amt ) d ON a.MaterialCode= d.MaterialCode \n"+
" ) TEMP1\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SAPCode= TEMP2.MaterialCode";
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SAPCode= TEMP2.MaterialCode";