//// str += string.Format(" and year='{0}' ", year);
////}
//if (!string.IsNullOrEmpty(version))
//{
//{
// str += string.Format(" and year='{0}' ", year);
// str += string.Format(" and version='{0}' ", version);
//}
//}
if(!string.IsNullOrEmpty(version))
{
str+=string.Format(" and version='{0}' ",version);
}
if(!string.IsNullOrEmpty(materialcode))
{
//// string sqlString = "select "+ string.Format(" {0} as Version ,",version) + "a.MaterialCode,isnull(b.qty,0) InvoiceQty,isnull(c.qty,0) SettleQty, (isnull(b.qty,0)-isnull(c.qty,0)) as DiffQty from (\n" +
str+=string.Format(" and materialcode='{0}' ",materialcode);
//// " select distinct MaterialCode from( \n"+
}
////"select distinct MaterialCode from Set_Invoice {0}\n" +
stringsqlString="select "+string.Format(" {0} as Version ,",version)+"a.MaterialCode,isnull(b.qty,0) InvoiceQty,isnull(c.qty,0) SettleQty, (isnull(b.qty,0)-isnull(c.qty,0)) as DiffQty from (\n"+
//// "union all\n" +
" select distinct MaterialCode from( \n"+
//// "select distinct MaterialCode from {1} {0}\n" +
"select distinct MaterialCode from Set_Invoice {0}\n"+
//// ") temp \n"+
"union all\n"+
//// ") as a\n" +
"select distinct MaterialCode from {1} {0}\n"+
//// "left join\n" +
") temp \n"+
//// "\n" +
") as a\n"+
//// "(select SUM(QTY) qty,MaterialCode from Set_Invoice {0} GROUP BY MaterialCode) b on a.MaterialCode=b.MaterialCode\n" +
"left join\n"+
//// "\n" +
//// "left join\n" +
//// "(select SUM(QTY) qty,MaterialCode from {1} {0} GROUP BY MaterialCode) c on a.MaterialCode=c.MaterialCode";
stringsqlString=
"SELECT \n"+string.Format(" '{0}' as Version ,",version)+"\n"+
" b.*,\n"+
" ISnull(\n"+
" c.Qty,\n"+
" IsNull( d.qty, 0 )) SettleQty,\n"+
"CASE\n"+
" \n"+
" \n"+
"(select SUM(QTY) qty,MaterialCode from Set_Invoice {0} GROUP BY MaterialCode) b on a.MaterialCode=b.MaterialCode\n"+
" WHEN e.Type = 'CP7报废' THEN\n"+
" isnull( e.Qty, 0 ) ELSE 0 \n"+
" END AS CP7ScrapQty,\n"+
"CASE\n"+
" \n"+
" \n"+
"left join\n"+
" WHEN e.Type = '索赔' THEN\n"+
"(select SUM(QTY) qty,MaterialCode from {1} {0} GROUP BY MaterialCode) c on a.MaterialCode=c.MaterialCode";
" 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";