string.Format(" '{0}' as Version ,",version)+"\n"+
" b.*,\n"+
" ISnull(\n"+
" c.Qty,\n"+
" IsNull( d.qty, 0 )) SettleQty,\n"+
" CASE\n"+
" \n"+
" WHEN e.Type = 'CP7报废' THEN\n"+
" isnull( e.Qty, 0 ) ELSE 0 \n"+
" END AS CP7ScrapQty,\n"+
" CASE\n"+
" \n"+
" WHEN e.Type = '索赔' THEN\n"+
" isnull( e.Qty, 0 ) ELSE 0 \n"+
" END AS ClaimQty,\n"+
" (\n"+
" b.InvoiceQty - ISnull(\n"+
" c.Qty,\n"+
" IsNull( d.qty, 0 ))) DiffQty,\n"+
" g.MaterialCode AS SapMaterialCode,\n"+
" g.MaterialDesc AS MaterialDesc, \n"+
" g.EstimateTypeDesc as SapMaterialGroup \n "+
" FROM\n"+
" (\n"+
" SELECT\n"+
" Factory,\n"+
" MaterialCode,\n"+
" SUM( QTY ) InvoiceQty,\n"+
" sum( amt ) InvoiceAmt,\n"+
" sum( amt )/ sum( Qty ) InvoicePrice \n"+
" FROM\n"+
" Set_Invoice \n"+
" WHERE\n"+
" version = '{0}' \n"+
" GROUP BY\n"+
" MaterialCode,\n"+
" Factory \n"+
" ) b\n"+
" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n"+
" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n"+
//" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode\n" +
" LEFT JOIN Set_material g ON b.MaterialCode = g.CustomerPartCode \n"+
" ) temp1\n"+
" LEFT JOIN (\n"+
" SELECT\n"+
" Price,\n"+
" MaterialCode \n"+
" FROM\n"+
" Set_PriceList \n"+
" WHERE\n"+
" version =(\n"+
" SELECT\n"+
" max( version ) \n"+
" FROM\n"+
" Set_PriceListVersion \n"+
" )) temp2 ON temp1.SapMaterialCode = temp2.MaterialCode";
string.Format(" '{0}' as Version ,",version)+"\n"+
" b.*,\n"+
" ISnull(\n"+
" c.Qty,\n"+
" IsNull( d.qty, 0 )) SettleQty,\n"+
" CASE\n"+
" \n"+
" WHEN e.Type = 'CP7报废' THEN\n"+
" isnull( e.Qty, 0 ) ELSE 0 \n"+
" END AS CP7ScrapQty,\n"+
" CASE\n"+
" \n"+
" WHEN e.Type = '索赔' THEN\n"+
" isnull( e.Qty, 0 ) ELSE 0 \n"+
" END AS ClaimQty,\n"+
" (\n"+
" b.InvoiceQty - ISnull(\n"+
" c.Qty,\n"+
" IsNull( d.qty, 0 ))) DiffQty,\n"+
" g.MaterialCode AS SapMaterialCode,\n"+
" g.MaterialDesc AS MaterialDesc, \n"+
" g.EstimateTypeDesc as SapMaterialGroup \n "+
" FROM\n"+
" (\n"+
" SELECT\n"+
" Factory,\n"+
" MaterialCode,\n"+
" SUM( QTY ) InvoiceQty,\n"+
" sum( amt ) InvoiceAmt,\n"+
" sum( amt )/ sum( Qty ) InvoicePrice \n"+
" FROM\n"+
" Set_Invoice \n"+
" WHERE\n"+
" version = '{0}' \n"+
" GROUP BY\n"+
" MaterialCode,\n"+
" Factory \n"+
" ) b\n"+
" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n"+
" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n"+
//" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode\n" +
" LEFT JOIN Set_material g ON b.MaterialCode = g.CustomerPartCode \n"+
" ) temp1\n"+
" LEFT JOIN (\n"+
" SELECT\n"+
" Price,\n"+
" MaterialCode \n"+
" FROM\n"+
" Set_PriceList \n"+
" WHERE\n"+
" version =(\n"+
" SELECT\n"+
" max( version ) \n"+
" FROM\n"+
" Set_PriceListVersion \n"+
" )) temp2 ON temp1.SapMaterialCode = temp2.MaterialCode";