stringsqlString=" select "+string.Format(" {0} as Version , ",version)+" r1.ErpMaterialCode, r2.Price, r1.SumPrice , r1.MaterialDesc, (isnull(r2.Price,0)-isnull(r1.SumPrice,0)) as diffPrice from \n"+
stringsqlString="SELECT\n"+
"( select ErpMaterialCode, MaterialDesc, SUM(Price) as SumPrice from(\n"+
" t1.ErpMaterialCode,\n"+
"select a.ErpMaterialCode, b.SettlementPartCode, a.MaterialDesc, (a.Qty * b.Price) as Price from\n"+
" t1.Price SumPrice,\n"+
"(SELECT ErpMaterialCode, MaterialDesc, SettleMaterialCode, Qty, Version ,CustomerCode \n"+
"inner join Set_settlement_part b on a.Version = b.Version and a.SettleMaterialCode = b.SettlementPartCode and a.CustomerCode = b.CustomerCode) temp group by ErpMaterialCode, MaterialDesc) r1 left join set_pricelist r2 "+
"FROM\n"+
" on r2.MaterialCode=r1.ErpMaterialCode and r2.Version='{0}'\n";
" (\n"+
" SELECT\n"+
" ErpMaterialCode,\n"+
" SUM( amt ) Price \n"+
" FROM\n"+
" (\n"+
" SELECT\n"+
" ErpMaterialCode,\n"+
" SettleMaterialCode,(\n"+
" Qty * isnull( b.Price, 0 )) amt \n"+
" FROM\n"+
" Set_MaterialRelationshipDetail a\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) AND type = 10 ) b ON a.SettleMaterialCode = b.MaterialCode \n"+
" ) temp1 \n"+
" GROUP BY\n"+
" ErpMaterialCode \n"+
" ) t1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) AND type = 10 ) t2 ON t1.ErpMaterialCode = t2.MaterialCode\n"+
" LEFT JOIN ( SELECT max( Id ) Id, MaterialCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc ) t3 ON t1.ErpMaterialCode = t3.MaterialCode";