how to replace blanks with values from another column

Hi All,

 

I am trying to populate blank cell with a value from another column, i.e. 

 

if 'country' is blank then populate with a value from 'country_1'

 

I tried the below, but it doesn't seem to work. 

 

CASE

WHEN LENGTH(`Country`)=0
THEN `Country_1`

END

 

Please help!

 

Thanks

Max

Comments

  • IFNULL (`country`, `country_1`)

    “There is a superhero in all of us, we just need the courage to put on the cape.” -Superman
  • rado98
    rado98 Contributor

    The previously proposed formula will fix your issue, however if you need to use case statement (for another reason) the following should work I think

     

    CASE

    WHEN TRIM(`Country`) = ''
    THEN `Country_1`

    ELSE `Country`

    END

  • rahul93
    rahul93 Contributor

    might want to use a case statement for blanks and nulls.

     

     

    Case when trim(`country`) = '' or `country` is null then `country` else `country` end