" ( c.ReceiptQty- d.Amt ) AS SettleInvoiceDiffQty,--发货与开票差异\n"+
" d.InvoicePrice,--开票单价\n"+
" 0 AS InvoiceMoney --开票金额\n"+
" \n"+
" temp1.期间,\n"+
" temp1.交货单号,\n"+
" temp1.发货日期,\n"+
" temp1.采购订单号,\n"+
" temp1.SAP编码,\n"+
" temp1.物料代码,\n"+
" temp1.物料描述,\n"+
" temp1.物料组,\n"+
" temp1.开票单价,\n"+
" temp1.数量差异,\n"+
" temp1.发货数量,\n"+
" temp1.开票数量,\n"+
" ISNULL( TEMP2.Price, 0 ) AS 定价,\n"+
" temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 \n"+
" FROM\n"+
" (\n"+
" SELECT\n"+
" t.PurchaseOrderNoText,\n"+
" t.LineNumber,\n"+
" t.PurchaseOrderNo,\n"+
" t.MaterialCode,\n"+
" MAX ( t.SpareDate ) SpareDate,\n"+
" t.DeliveryOrderNo,\n"+
" SUM ( t.InvoicedQty ) AS InvoicedQty \n"+
" a.Version AS 期间,\n"+
" b.WMSDeliveryNote AS 交货单号,\n"+
" b.SpareDate AS 发货日期,\n"+
" a.PurchaseOrderNo AS 采购订单号,\n"+
" c.MaterialCode AS SAP编码,\n"+
" a.MaterialCode AS 物料代码,\n"+
" c.MaterialDesc AS 物料描述,\n"+
" c.EstimateTypeDesc AS 物料组,\n"+
" a.PurchasePriceNoTax AS 开票单价,\n"+
" 0 AS 数量差异,\n"+
" ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n"+
" ISNULL( b.ReceiptQty, 0 ) AS 开票数量 \n"+
" FROM\n"+
" Set_SparePart t \n"+
" (SELECT SUM( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart GROUP BY PurchaseOrderNo, MaterialCode, Version, PurchasePriceNoTax ) AS a\n"+
" LEFT OUTER JOIN Set_WMSSparePart AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" t.Version= '{0}' \n"+
" GROUP BY\n"+
" t.PurchaseOrderNo,\n"+
" t.MaterialCode,\n"+
" t.SpareDate,\n"+
" t.DeliveryOrderNo,\n"+
" t.LineNumber,\n"+
" t.PurchaseOrderNoText \n"+
" ) AS a\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_WMSSparePart c ON a.PurchaseOrderNo= c.WMSDeliveryNote \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode, Amt FROM set_invoice WHERE version = '{0}' GROUP BY materialcode, Amt ) d ON a.MaterialCode= d.MaterialCode \n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SAPCode= TEMP2.MaterialCode";
" ( a.Version = '{0}' )) AS temp1\n"+
" LEFT OUTER JOIN (\n"+
" SELECT\n"+
" Price,\n"+
" MaterialCode \n"+
" FROM\n"+
" Set_PriceList \n"+
" WHERE\n"+
" (\n"+
" Version = ( SELECT MAX(Version) AS Expr1 FROM Set_PriceList ))) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" ( SELECT sum( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart where Version='{0}' GROUP BY PurchaseOrderNo, MaterialCode ) A\n"+
" LEFT JOIN ( SELECT sum( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) B ON A.MaterialCode = B.MaterialCode \n"+