" ( c.ReceiptQty- d.Amt ) AS SettleInvoiceDiffQty,--发货与开票差异\n"+
" temp1.开票数量,\n"+
" d.InvoicePrice,--开票单价\n"+
" ISNULL( TEMP2.Price, 0 ) AS 定价,\n"+
" 0 AS InvoiceMoney --开票金额\n"+
" temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 \n"+
" \n"+
" FROM\n"+
" FROM\n"+
" (\n"+
" (\n"+
" SELECT\n"+
" SELECT\n"+
" t.PurchaseOrderNoText,\n"+
" a.Version AS 期间,\n"+
" t.LineNumber,\n"+
" b.WMSDeliveryNote AS 交货单号,\n"+
" t.PurchaseOrderNo,\n"+
" b.SpareDate AS 发货日期,\n"+
" t.MaterialCode,\n"+
" a.PurchaseOrderNo AS 采购订单号,\n"+
" MAX ( t.SpareDate ) SpareDate,\n"+
" c.MaterialCode AS SAP编码,\n"+
" t.DeliveryOrderNo,\n"+
" a.MaterialCode AS 物料代码,\n"+
" SUM ( t.InvoicedQty ) AS InvoicedQty \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"+
" 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"+
" WHERE\n"+
" t.Version= '{0}' \n"+
" ( a.Version = '{0}' )) AS temp1\n"+
" GROUP BY\n"+
" LEFT OUTER JOIN (\n"+
" t.PurchaseOrderNo,\n"+
" SELECT\n"+
" t.MaterialCode,\n"+
" Price,\n"+
" t.SpareDate,\n"+
" MaterialCode \n"+
" t.DeliveryOrderNo,\n"+
" FROM\n"+
" t.LineNumber,\n"+
" Set_PriceList \n"+
" t.PurchaseOrderNoText \n"+
" WHERE\n"+
" ) AS a\n"+
" (\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" Version = ( SELECT MAX(Version) AS Expr1 FROM Set_PriceList ))) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" 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";
" ( 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"+