Skip to content
Advertisement

Apply lowercase in specific column for certain group of countries in BQ?

I need to apply lowercase to product_name column for countries like FR, ES, but for the rest of them CA, IL, DE should be without any changes. I’m tryin with this query, but something doesn’t work:

 SELECT
    id
    ,brand
    ,cern
    ,cern_3
    ,backpack
    ,qutoation
    ,product_name 
    ,CASE WHEN country_code in ('FR', 'ES') then lower(product_name) end
    ,category
    ,country_code
    ,timestamp
FROM table.name

Advertisement

Answer

Your query probably returns null for other countries, so as @forpas suggested in comments add else:

CASE WHEN country_code in ('FR', 'ES') then lower(product_name) else product_name end
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement