Hallo zusammen,
danke erstmal für die vielen Antworten. Ich habe jetzt eine für mich akzeptable Lösung gefunden. Vielleicht ein bisschen umständlich, aber sie funktioniert.
Code:
select facility.*,
province.AaLong as AaProvinceLong,
province.AaShort as AaProvinceShort,
province.AaCenter as AaProvinceCenter,
district.AaName as AaDistrictName,
country.AaLong as AaCountryLong,
country.AaShort as AaCountryShort,
facility_type.AaShort as AaFacilityTypeShort,
facility_type.AaLong as AaFacilityTypeLong,
(AaProvinceShort + AaFacilityTypeShort + substring("000" + cast(facility.AiCode as string), Length("000" + cast(facility.AiCode as string)) - 3, Length("000" + cast(facility.AiCode as string)))) as AaCode
from (facility
LEFT JOIN province
ON facility.AiProvince = province.SiProvince
LEFT JOIN district
ON facility.AiDistrict = district.SiDistrict
LEFT JOIN country
ON facility.AiCountry = country.SiCountry
LEFT JOIN facility_type
ON facility.AiFacilitytype = facility_type.SiFacilitytype
)
order by AaCode ASC;
Ich bin aber für weitere Vorschläge offen, wie man es komplett über
SQL lösen kann.