From: Frank Swarbrick on
How can I fix this so that it doesn't do essentially the same scan
twice, but it gives the same results (a single row where
IDENTITY_MODIFIER is either 'identityoverride' or '' and
ROWCHANGETIMESTAMP_MODIFIER is either 'rowchangetimestampoverride' or ''?

select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverride'
else ''
end as identity_modifier
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimestamp = 'Y'
) then 'rowchangetimestampoverride'
else ''
end as rowchangetimestamp_modifier
from sysibm.sysdummy1;

Results:

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.