" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" INNER JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode where a.VERSION='{0}'\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \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"+
" ( 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";
" 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"+
" 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"+
" ) A\n"+
" LEFT 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"+
" ) B ON A.SapCode = B.SapCode WHERE (A.ReceiptQty - ISNULL( B.ReceiptQty, 0 )) <> 0";
" (SELECT SUM( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart GROUP BY PurchaseOrderNo, MaterialCode, Version, PurchasePriceNoTax ) AS a\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 = 'not90' \n"+
" GROUP BY\n"+
" PurchaseOrderNo,\n"+
" MaterialCode,\n"+
" Version,\n"+
" PurchasePriceNoTax \n"+
" ) AS a\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"+
" WHERE\n"+
" ( a.Version = '{0}' )) AS temp1\n"+
" LEFT OUTER JOIN (\n"+
" SELECT\n"+
" Price,\n"+
" MaterialCode \n"+
" FROM\n"+
" Set_PriceList \n"+
" WHERE\n"+
" (\n"+
" Version = ( SELECT MAX(Version) AS Expr1 FROM Set_PriceList ))) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
" ( 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.采购订单号";