" LEFT JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" INNER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) 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";
//" ( a.Qty- c.WMSDeliveryQty ) AS SettleWMSDiffQty,--结算与发货差异\n" +
//" 0 AS SettleInvoiceDiffQty,--结算与发货差异\n" +
//" a.Qty AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n" +
//" d.InvoicePrice,--开票单价\n" +
//" 0 AS InvoiceMoney,--开票金额\n" +
//" '' DeliveryOrderNo --出库单号\n" +
//" \n" +
//" FROM\n" +
//" Set_KanBanSettle AS a\n" +
//" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\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" +
//" ) TEMP1\n" +
//" LEFT JOIN ( SELECT Price, --定价\n" +
//" MaterialCode --厂内物料号\n" +
//" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n" +
//"WHERE 1=1 ";
stringsqlString="SELECT\n"+
" * ,\n"+
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount,--金额\n"+
" ISNULL( Price * Qty, 0 ) AS SettlePrice,--结算金额\n"+
" ( Price - InvoicePrice ) AS InvoiceDiffPrice,--单价差异\n"+
" ( a.Qty- c.WMSDeliveryQty ) AS SettleWMSDiffQty,--结算与发货差异\n"+
" 0 AS SettleInvoiceDiffQty,--结算与发货差异\n"+
" a.Qty AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n"+
" d.InvoicePrice,--开票单价\n"+
" 0 AS InvoiceMoney,--开票金额\n"+
" '' DeliveryOrderNo --出库单号\n"+
" \n"+
" FROM\n"+
" Set_KanBanSettle AS a\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\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"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n"+
"WHERE 1=1 ";
" * ,\n"+
" ISNULL( Price * Qty, 0 ) AS InvoiceMoney,--开票金额\n"+
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount,--金额\n"+
" ISNULL( Price * Qty, 0 ) AS SettlePrice,--结算金额\n"+
" ( Price - InvoicePrice ) AS InvoiceDiffPrice,--单价差异\n"+
" ( a.Qty- c.WMSDeliveryQty ) AS SettleWMSDiffQty,--结算与发货差异\n"+
" 0 AS SettleInvoiceDiffQty,--结算与发货差异\n"+
" a.Qty AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n"+
" d.InvoicePrice --开票单价\n"+
" \n"+
" FROM\n"+
" Set_KanBanSettle AS a\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\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 \n"+
" WHERE\n"+
" a.VERSION= '{0}' \n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \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" +
//" 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 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"+
" ( 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}' ) \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 \n"+
"ORDER BY\n"+
" 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";