" (c.ReceiptQty-d.Amt) as SettleInvoiceDiffQty,--发货与开票差异 \n"+
" d.InvoicePrice,--开票单价 \n"+
" 0 as InvoiceMoney --开票金额 \n"+
" \n"+
" FROM \n"+
" Set_SparePart 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 ";
stringsqlString="SELECT\n"+
" * ,\n"+
" ( Price - InvoicePrice ) AS InvoiceDiffPrice,--单价差异\n"+
" ( c.ReceiptQty- d.Amt ) AS SettleInvoiceDiffQty,--发货与开票差异\n"+
" d.InvoicePrice,--开票单价\n"+
" 0 AS InvoiceMoney --开票金额\n"+
" \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"+
" FROM\n"+
" Set_SparePart t \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";