//" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n" +
//" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' AND PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n" +
//" AND temp1.MaterialCode = temp2.MaterialCode \n" +
//" ) \n" +
//" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n" +
//" AND A.MaterialCode = C.MaterialCode \n" +
//" WHERE\n" +
//" ( a.Version = '{0}' ) \n" +
//" ) AS temp1\n" +
//" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) temp3 ON temp1.采购订单号 = temp3.Code \n" +
//" AND temp1.SAP编码= temp3.MaterialCode\n" +
//" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" +
//" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n" +
//" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n" +
//" ) AS temp1\n" +
//" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = ( SELECT MAX ( VERSION ) FROM Set_PriceList ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" +
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n"+
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' AND PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" ) \n"+
" ) \n"+
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n"+
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = ( SELECT MAX ( VERSION ) FROM Set_PriceList ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n"+
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" ) \n"+
" ) \n"+
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n"+
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' GROUP BY MaterialCode, PurchasePriceNoTax ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" FROM\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" (\n"+
" ) AS temp1\n"+
" SELECT SUM\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" ( ReceiptQty ) AS ReceiptQty,\n"+
" SUM ( InvoicedQty ) InvoicedQty,\n"+
" MaterialCode,\n"+
" PurchasePriceNoTax \n"+
" FROM\n"+
" Set_SparePart \n"+
" WHERE\n"+
" Extend != 'is90' \n"+
" AND Version = '{0}' \n"+
" GROUP BY\n"+
" MaterialCode,\n"+
" PurchasePriceNoTax \n"+
" ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS a\n"+
// " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS a\n" +
" LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\n"+
// " LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\n" +
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
// " LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n" +
" WHERE\n"+
// " WHERE\n" +
" ( b.MaterialCode IS NULL ) \n"+
// " ( b.MaterialCode IS NULL ) \n" +
" ) AS temp1\n"+
// " ) AS temp1\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
// " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) AS a\n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart WHERE PurchaseOrderNo is not null and PurchaseOrderNo!='' GROUP BY PurchaseOrderNo, MaterialCode ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) a\n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart WHERE PurchaseOrderNo is not null and PurchaseOrderNo!='' GROUP BY PurchaseOrderNo, MaterialCode ) a\n"+
" INNER JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n"+
" INNER JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+