I'm having a hard time performing a query on a customer table. I need to fetch two columns ( nomeCli
and nomeFantasiaCli
) and transform them into one: Nome
.
In short, when the client name is not populated in the client table, I will use the client's business name.
I'm using the following query:
SELECT (CASE nomeCli
WHEN NULL THEN nomeFantasiaCli
ELSE nomeCli
END ) AS Nome
FROM cliente
ORDER BY Nome ASC
The query works. The problem is that it only populates the new column Nome
with only nomeCli
. If this nomeCli
is empty, it should populate with nomeFantasiaCli
, but this does not occur. I've even tried to change WHEN NULL
to WHEN ''
. But it did not help.
How to solve the problem?