" ) 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"+
" PurchaseOrderNo != 'BM' \n"+
" AND PurchaseOrderNo LIKE '%D30%' \n"+
" OR PurchaseOrderNo LIKE '%D60%' \n"+
" OR PurchaseOrderNo LIKE '%D90%' \n"+
" ) AS b ON a.SapCode = b.SapCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc ) AS c ON b.SapCode = c.MaterialCode \n"+
" WHERE\n"+
" ( a.Version = '202112' ) \n"+
" ( a.Version = '{0}' ) \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
//" ) AS b ON a.MaterialCode = b.MaterialCode\n" +
//" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" +
//" WHERE\n" +
//" ( a.Version = '{0}' ) \n" +
//" ) AS temp1\n" +
//" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode ORDER BY temp1.采购订单号";
// " ( 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" +
// " AND A.PurchaseOrderNo = B.PurchaseOrderNo \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"+
" LEFT OUTER JOIN (\n"+
" SELECT SUM\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" PurchaseOrderNo,\n"+
" SapCode,\n"+
" MaterialCode,\n"+
" WMSDeliveryNote,\n"+
" SpareDate \n"+
" FROM\n"+
" Set_WMSSparePart \n"+
" GROUP BY\n"+
" PurchaseOrderNo,\n"+
" SapCode,\n"+
" MaterialCode,\n"+
" WMSDeliveryNote,\n"+
" SpareDate \n"+
" ) AS b ON a.SapCode = b.SapCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc ) AS c ON b.SapCode = c.MaterialCode \n"+
" WHERE\n"+
" ( a.Version = '{0}' ) \n"+
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode ORDER BY temp1.采购订单号";
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
"ORDER BY\n"+
" temp1.采购订单号";
stringaddwhere=string.Empty;
stringaddSqlStr=string.Format(sqlString,version);
//if (!string.IsNullOrEmpty(purchaseOrderNo))
//{
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
" ( 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"+
" AND A.PurchaseOrderNo = B.PurchaseOrderNo";
" (\n"+
" SELECT\n"+
" t.ReceiptQty,\n"+
" t.PurchaseOrderNo,\n"+
" t.Version,\n"+
" t.PurchasePriceNoTax,\n"+
" ( SELECT MaterialCode FROM Set_material WHERE CustomerPartCode = t.MaterialCode ) AS SapCode \n"+