//" ( SELECT MaterialCode FROM Set_material WHERE CustomerPartCode = t.MaterialCode ) AS SapCode \n" +
//" FROM\n" +
//" (\n" +
//" SELECT SUM\n" +
//" ( ReceiptQty ) AS ReceiptQty,\n" +
//" PurchaseOrderNo,\n" +
//" MaterialCode,\n" +
//" Version,\n" +
//" PurchasePriceNoTax,\n" +
//" InvoicedQty,\n" +
//" PurchaseOrderNoText,\n" +
//" AmountNoTax \n" +
//" FROM\n" +
//" Set_SparePart \n" +
//" WHERE\n" +
//" Extend != 'is90' \n" +
//" GROUP BY\n" +
//" PurchaseOrderNo,\n" +
//" MaterialCode,\n" +
//" Version,\n" +
//" PurchasePriceNoTax,\n" +
//" InvoicedQty,\n" +
//" PurchaseOrderNoText,\n" +
//" AmountNoTax \n" +
//" ) t \n" +
//" ) AS a\n" +
//" INNER 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 \n" +
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode, SpareDate FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode, SpareDate ) 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"+
" WHERE\n"+
" ( a.Version = '{0}' and b.MaterialCode is NULL ) \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";
stringaddwhere=string.Empty;
stringaddSqlStr=string.Format(sqlString,version);
//if (!string.IsNullOrEmpty(purchaseOrderNo))
//{
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
//}
//else if (!string.IsNullOrEmpty(sapCode))
//{
// addwhere += string.Format(" AND SAPCode LIKE '{0}%' ", sapCode);
//}
//else if (!string.IsNullOrEmpty(matialCode))
//{
// addwhere += string.Format(" AND MaterialCode LIKE '{0}%' ", matialCode);
//}
//else if (!string.IsNullOrEmpty(begintime)&& !string.IsNullOrEmpty(endtime))
//{
// addwhere += string.Format(" AND OrderDate BETWEEN '{0}' AND '{1}' ", begintime, endtime);
" ) 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"+
" ( 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"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, 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"+
" 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 \n"+
" (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_20 ) ) TEMP2 ON TEMP1.SAPCode= TEMP2.MaterialCode ";
stringaddwhere=string.Empty;
stringaddSqlStr=string.Format(sqlString,version);
//if (!string.IsNullOrEmpty(purchaseOrderNo))
//{
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
" LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" b.PurchaseOrderNo IS NULL \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"+