I have a column in my database that contains campaign_name, the country codes are present in the names and I want to be able to extract them and transform them into their normal names as well as create a new column called country name that includes the country from each campaign. This is the snippet of the code:
WHEN LOWER(cmp.campaign_name) LIKE '%canada%' THEN 'Canada'
WHEN LOWER(cmp.campaign_name) LIKE '%uk%' THEN 'United Kingdom'
WHEN (cmp.campaign_name) LIKE '%US%' THEN 'United States'
ELSE 'other'
END AS country_name.
This is an example of the campaign name "campaign_UK-US_receiver" The problem with this code is that unlike a for loop in most programming languages I could create a list of country and check for the first occurrence of words that are the same as in the list, then return the country name of the respect code. The problem with using SQL is that based on the first statement which is for Canada if the first row SQL iterates over is Canada it'll get it right but if its on the next statement which is for UK. if it see's a campaign name like "campaign_Canada_UK_receiver" instead of picking Canada as its the first occurrence of the countries it'll pick UK because it has executed Canada already.