//" ( 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" +
" ) 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, SpareDate FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode, SpareDate ) AS b ON a.MaterialCode = b.MaterialCode\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}' and b.MaterialCode is NULL ) \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";
stringaddwhere=string.Empty;
stringaddSqlStr=string.Format(sqlString,version);
" 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"+
" ) union2";
//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);
" (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);
" ( 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"+
" a.PurchaseOrderNo AS 采购订单号,\n"+
" a.WMSDeliveryNote AS 交货单号,\n"+
" a.SpareDate AS 交货日期,\n"+
" a.MaterialCode AS 物料代码,\n"+
" ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n"+
" c.MaterialCode AS SAP编码,\n"+
" c.MaterialDesc AS 物料描述,\n"+
" c.EstimateTypeDesc AS 物料组,\n"+
" b.Version AS 期间,\n"+
" b.PurchaseOrderNoText AS 采购订单文本,\n"+
" b.PurchasePriceNoTax AS 开票单价,\n"+
" 0 AS 数量差异,\n"+
" ISNULL( b.InvoicedQty, 0 ) AS 开票数量 ,\n"+
" ISNULL( b.AmountNoTax, 0 ) AS 开票金额 \n"+
" FROM\n"+
" Set_SparePart \n"+
" Set_WMSSparePart a\n"+
" 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"+
" 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"+