Whenever you find yourself trying to do things with multi-column sets, you've probably got your schema wrong.
It would almost certainly be easier to separate A, B, C and D into separate rows in a separate table, tie them back to the row in the original table and create a JOIN
-type query.
Alternatively, if only one is ever non-NULL, I would opt for two columns, type (A, B, C or D) and value. Then you're not wasting the columns in every row, and the queries are immeasurably easier (assuming the types are the same).
However, you can do it this way with case
:
select case
when A is not null then 'A'
when B is not null then 'B'
when C is not null then 'C'
else 'D'
end
from ...
The syntax may not be exactly correct, you'll need to look it up. IIt's not something I usually do since I consider it a bad idea (per-row functions in select never scale well).