I’m creating a case subquery that does work, however I am sure there must be an easier way of doing this?
The aim of the query is when billgrp_desc like ‘30%’, then display billgrp_desc from tbm.billgrp table.
Otherwise display matter_code from hbm.matter table when billgrp_desc not like ‘30%’
The query is below:
select
case
when bllgrp_desc like '30%' then 'billgrp_desc'
end
from tbm.billgrp
union
select
case
when exists (select billgrp_desc
from tbm.billgrp
where billgrp_desc not like '30%') then 'matter_code'
end
from hbm.matter
Try this, I am assuming Matter_code is a field from the matter table