" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) c ON a.ItemCode = c.MaterialCode\n"+
" LEFT JOIN set_material d ON a.ItemCode = d.CustomerPartCode\n"+
" LEFT JOIN (select max(CreationTime) CreateTime,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) e ON a.ErpMaterialCode = e.MaterialCode {1} \n"+
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) e ON a.ErpMaterialCode = e.MaterialCode {1} \n"+
" LEFT JOIN Set_material c ON a.MaterialCode = c.CustomerPartCode {0}\n"+
" ) temp1\n"+
" LEFT JOIN Set_material temp2 ON temp1.ParentSapMaterialCode = temp2.MaterialCode \n"+
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) temp2 ON temp1.ParentSapMaterialCode = temp2.MaterialCode \n"+
" left join (select * from Set_Unsettle where version='{1}') f \n"+
" on a.MaterialCode=f.MaterialCode and a.KENNCode2=f.KENNCode and a.ChassisNumber2=f.ChassisNumber \n"+
" LEFT JOIN Set_material B ON a.MaterialCode = b.CustomerPartCode \n"+
" LEFT JOIN Set_material d ON a.ParentSapMaterialCode = d.MaterialCode \n"+
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) d ON a.ParentSapMaterialCode = d.MaterialCode \n"+
" ) temp1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) ) temp2 ON temp1.SapMaterialCode = temp2.MaterialCode";