" temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 \n"+
"FROM\n"+
" (\n"+
" SELECT\n"+
" a.Version AS 期间,\n"+
" b.WMSDeliveryNote AS 交货单号,\n"+
" b.SpareDate AS 发货日期,\n"+
" b.PurchaseOrderNo AS 采购订单号,\n"+
" b.SapCode AS SAP编码,\n"+
" b.MaterialCode AS 物料代码,\n"+
" c.MaterialDesc AS 物料描述,\n"+
" c.EstimateTypeDesc AS 物料组,\n"+
" a.PurchasePriceNoTax AS 开票单价,\n"+
" 0 AS 数量差异,\n"+
" ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n"+
" ISNULL( b.ReceiptQty, 0 ) AS 开票数量 \n"+
" FROM\n"+
" (\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"+
" FROM\n"+
" (\n"+
" SELECT SUM\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" PurchaseOrderNo,\n"+
" MaterialCode,\n"+
" Version,\n"+
" PurchasePriceNoTax \n"+
" FROM\n"+
" Set_SparePart \n"+
" WHERE\n"+
" Extend = 'is90' \n"+
" GROUP BY\n"+
" PurchaseOrderNo,\n"+
" MaterialCode,\n"+
" Version,\n"+
" PurchasePriceNoTax \n"+
" ) t \n"+
" ) AS a\n"+
" INNER JOIN (\n"+
" SELECT\n"+
" WMSDeliveryNote,\n"+
" SpareDate,\n"+
" MaterialCode,\n"+
" ReceiptQty,\n"+
" PurchaseOrderNo,\n"+
" SapCode \n"+
" FROM\n"+
" Set_WMSSparePart \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"+
" ) 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.采购订单号";
" ) 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"+
" WHERE\n"+
" PurchaseOrderNo != 'BM' \n"+
" ( a.Version = '{0}' ) \n"+
" AND PurchaseOrderNo LIKE '%D30%' \n"+
" ) AS temp1\n"+
" OR PurchaseOrderNo LIKE '%D60%' \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"+
" OR PurchaseOrderNo LIKE '%D90%' \n"+
"ORDER BY\n"+
" ) B ON A.SapCode = B.SapCode WHERE (A.ReceiptQty - ISNULL( B.ReceiptQty, 0 )) <> 0";
// " ( 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 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"+
" LEFT OUTER JOIN (\n"+
" SELECT SUM\n"+
" SELECT SUM\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" PurchaseOrderNo,\n"+
" PurchaseOrderNo,\n"+
" SapCode,\n"+
" MaterialCode,\n"+
" MaterialCode,\n"+
" Version,\n"+
" WMSDeliveryNote,\n"+
" PurchasePriceNoTax \n"+
" SpareDate \n"+
" FROM\n"+
" FROM\n"+
" Set_SparePart \n"+
" Set_WMSSparePart \n"+
" WHERE\n"+
" Extend = 'not90' \n"+
" GROUP BY\n"+
" GROUP BY\n"+
" PurchaseOrderNo,\n"+
" PurchaseOrderNo,\n"+
" SapCode,\n"+
" MaterialCode,\n"+
" MaterialCode,\n"+
" Version,\n"+
" WMSDeliveryNote,\n"+
" PurchasePriceNoTax \n"+
" SpareDate \n"+
" ) AS a\n"+
" ) AS b ON a.SapCode = b.SapCode\n"+
" LEFT OUTER JOIN Set_WMSSparePart AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \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"+
" AND a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" WHERE\n"+
" ( a.Version = '{0}' ) \n"+
" ( a.Version = '{0}' ) \n"+
" ) AS temp1\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;
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 sum( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart where Version='{0}' GROUP BY PurchaseOrderNo, MaterialCode ) A\n"+
" (\n"+
" LEFT JOIN ( SELECT sum( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) B ON A.MaterialCode = B.MaterialCode \n"+
" SELECT\n"+
" AND A.PurchaseOrderNo = B.PurchaseOrderNo";
" t.ReceiptQty,\n"+
" t.PurchaseOrderNo,\n"+
" t.Version,\n"+
" t.PurchasePriceNoTax,\n"+
" ( SELECT MaterialCode FROM Set_material WHERE CustomerPartCode = t.MaterialCode ) AS SapCode \n"+