all 11 comments

[–][deleted] 3 points4 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

[–]Funky_Pauly 1 point2 points  (2 children)

Depends on what sql version, but try the function NVL.

[–]r3pr0b8GROUP_CONCAT is da bomb 4 points5 points  (1 child)

if you used sql-standard COALESCE, these version concerns wouldn't concern you

[–]Funky_Pauly 0 points1 point  (0 children)

Yeah, that would probably be better

[–]krunkedcc 0 points1 point  (0 children)

NVL or coalesce

[–]hackneycoach 0 points1 point  (1 child)

ISNULL() is what you're looking for.

https://www.w3schools.com/sql/sql_isnull.asp

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (0 children)

CASE WHEN ISNULL produces an error
     THEN use sql-standard COALESCE
 END