//" ( 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"+
" c.MaterialDesc AS 物料描述,\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"+
" c.EstimateTypeDesc AS 物料组,\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"+
" a.PurchasePriceNoTax AS 开票单价,\n"+
" WHERE\n"+
" 0 AS 数量差异,\n"+
" ( a.Version = '{0}' and b.MaterialCode is NULL ) \n"+
" ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n"+
" ) AS temp1\n"+
" ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\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";
" ISNULL( a.AmountNoTax, 0 ) AS 开票金额 \n"+
stringaddwhere=string.Empty;
" FROM\n"+
stringaddSqlStr=string.Format(sqlString,version);
" (\n"+
" SELECT SUM\n"+
//if (!string.IsNullOrEmpty(purchaseOrderNo))
" ( ReceiptQty ) AS ReceiptQty,\n"+
//{
" PurchaseOrderNo,\n"+
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
" MaterialCode,\n"+
//}
" Version,\n"+
//else if (!string.IsNullOrEmpty(sapCode))
" PurchasePriceNoTax,\n"+
//{
" InvoicedQty,\n"+
// addwhere += string.Format(" AND SAPCode LIKE '{0}%' ", sapCode);
" PurchaseOrderNoText,\n"+
//}
" AmountNoTax \n"+
//else if (!string.IsNullOrEmpty(matialCode))
" FROM\n"+
//{
" Set_SparePart \n"+
// addwhere += string.Format(" AND MaterialCode LIKE '{0}%' ", matialCode);
" GROUP BY\n"+
//}
" PurchaseOrderNo,\n"+
//else if (!string.IsNullOrEmpty(begintime)&& !string.IsNullOrEmpty(endtime))
" MaterialCode,\n"+
//{
" Version,\n"+
// 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;
stringaddwhere=string.Empty;
stringaddSqlStr=string.Format(sqlString,version);
stringaddSqlStr=string.Format(sqlString,version);
//if (!string.IsNullOrEmpty(purchaseOrderNo))
//if (!string.IsNullOrEmpty(purchaseOrderNo))
//{
//{
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
// addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo);
" ( SELECT MaterialCode FROM Set_material WHERE CustomerPartCode = t.MaterialCode ) AS SapCode \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"+
" FROM\n"+
" (\n"+
" Set_WMSSparePart a\n"+
" SELECT SUM\n"+
" LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" PurchaseOrderNo,\n"+
" WHERE\n"+
" MaterialCode,\n"+
" b.PurchaseOrderNo IS NULL \n"+
" Version,\n"+
" ) AS temp1\n"+
" PurchasePriceNoTax \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"+