In my Oracle database, I have a table called Customers. There are fields for name, zip, city etc., but there are also fields for invoicename, invoicezip and invoicecity. For some records the invoicespecific fields are not set, and in that case the invoice method should use the information from name, zip and city.
I use the following query now:
select
case when c.InvoiceName is null then c.Name else c.InvoiceName end as Name,
case when c.InvoiceName is null then c.Zip else c.InvoiceZip end as Zip,
case when c.InvoiceName is null then c.City else c.InvoiceCity end as City
<...>
from
Customers c
where
Accountnumber=:accountnumber
Note that the check is on InvoiceName only. If that value is set I want to return all the invoice-specific fields, if not I want to return all the "non-invoice-specific" fields.
What I would like to do is something like this
select
case when c.InvoiceName is not null
then
c.InvoiceName as Name,
c.InvoiceZip as Zip,
c.InvoiceCity as City
<...>
else
c.Name,
c.Zip,
c.City
<...>
end
from
customers c
Is there way to do this or something like it?