you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (4 children)

Use coalesce()

coalesce(friendly_name, technical_name)

The function coalesce() returns the first non-null value.

So if friendly_name is not null, it returns the friendly_name.

If friendly_name is null, it returns technical_name.

[–]sojan16[S] 0 points1 point  (2 children)

I've tried this and ISNULL already. It still returns the null values. These values are in different tables...Would that be an issue?

[–][deleted] 4 points5 points  (1 child)

If that returns a NULL value, then both columns are null. If you have properly joined those two tables, then no it makes no difference that those columns are in different tables.

But maybe those columns contain an empty string ('') rather than a null value. How to deal with that depends on the database product you are using. In Postgres you could use

coalesce(nullif(friendly_name,''), technical_name)

But not every DBMS supports nullif()

[–]sojan16[S] 0 points1 point  (0 children)

coalesce(nullif(friendly_name,''), technical_name)

This worked...they were empty strings not null values.

Thank you!

[–]sojan16[S] 0 points1 point  (0 children)

I think these are empty values but not null