Create new column based on 4 different columns with no null data


I have four phone fields (Phone1, Phone2, Phone3, Phone4). I want to create a new column named primPhone which would be a duplicate of column Phone1. Then all null or blank values in primPhone, I want to add the Phone2 data that does not have null or blank values. And then same with Phone3 and Phone4.

The end result would be primPhone would have Phone1 data as primary and then all blanks or null would have Phone2 and then repeat Phone3 and Phone4.

For those who know SQL, this is how the SQL statement would be

UPDATE "13671_test1"
SET "cm_landline" =
WHEN "landlinedataaxle" IS NOT NULL THEN "landlinedataaxle"
WHEN "landlineall" IS NOT NULL THEN "landlineall"
WHEN "landlineneustar" IS NOT NULL THEN "landlineneustar"
WHEN "landlineabev" IS NOT NULL THEN "landlineabev"
ELSE "cm_landline"
"cm_landline" IS NULL

Hello Kyle and welcome to the Community!

You can use the coalesce() function:


See the example below:
coalesce.morph (2.8 KB)
data.csv (62 Bytes)

1 Like