I have a table of countries and their abbreviations with a column called code
with the abbreviations and a column called name
that contains the country names.
I need to iterate through a foreign address and look up each word until I find a match in the table (i.e. the country) and retrieve the abbreviation for a case statement.
This won't be done on all records, only certain ones that would be larger than a field of a 60 chars in a file I'm building.
So What I need to do is something to affect of:
SELECT
CASE WHEN address2 & foreign_address > 60
THEN split and iterate through '12345 MY SUPER LONG ADDRESS IN THE PHILIPPINES' and look up
each string until PHILIPPINES is matched in the country_codes table and 'PH' is returned
END
This is the best way I can think to handle this situation short of truncating the address which I don't want to do for obvious reasons. This also needs to be dynamic based on different addresses and countries.
My biggest challenge at this point is breaking up the string and doing a look up on each string fragment.