I have the following:
Select Coalesce(Other,Industry) Ind from registration
The thing is that Other
can be an empty string or
Use a CASE
expression or NULLIF
:
SELECT COALESCE(NULLIF(Other,''),Industry) Ind FROM registration
You can also use a short-cut knowing that NULL <> ''
doesn't evaluate to TRUE
...
CASE WHEN other <> '' THEN other ELSE industry END
The logic then works out as follows...
CASE WHEN 'fubar' <> '' THEN other ELSE industry END
=> CASE WHEN true THEN other ELSE industry END
=> other
CASE WHEN '' <> '' THEN other ELSE industry END
=> CASE WHEN false THEN other ELSE industry END
=> industry
CASE WHEN NULL <> '' THEN other ELSE industry END
=> CASE WHEN NULL THEN other ELSE industry END
=> industry
try this
Select Coalesce(nullif(Other,''),Industry) Ind from registration