select * from code_country select * from import_cargo select * from import_main select m.contractno,ca.id,c.country, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=9000 and EnumValueID=c.tariff) as tariff, case c.tariff when 0 then ci.tax_zhg when 1 then ci.tax_pt end tax, ci.tax_zz from import_cargo ca left join import_main m on m.contractno=ca.contractno left join code_country c on m.countryid=c.countryid left join import_cargoinfo ci on ci.id=ca.cargoinfo_id select c.country, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=9000 and EnumValueID=c.tariff) as tariff, case c.tariff when 0 then ci.tax_zhg when 1 then ci.tax_pt/100 end tax, ci.tax_zz/100 tax_zz from import_cargoinfo ci left join import_main m on m.contractno=ca.contractno left join code_country c on m.countryid=c.countryid where countryid in('GB','ES') select ci.id,name,code+'_'+name codeandname, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=9000 and EnumValueID=cc.tariff) as tariff, case cc.tariff when 0 then ci.tax_zhg/100 when 1 then ci.tax_pt/100 end tax, ci.tax_zz/100 as tax_zz from code_country cc,import_cargoinfo ci where --countryid in('GB','ES') and code='0201300090' select * from code_currency