I am trying to create derived table using below query but I am struck , I want to use below original query case statement alias name nn_due_date for another case statement in original query calculation but when I use I am getting error ORA - 00904: new_due_date":invalid identifier "
can you please help me, I want to use like below
case when a.DW_DX_DCRP_STRT_DT - DCRP_CRE_DT <= nn_due_date
then 1 else 0
end as wit_45_ct,
case when a.DW_DX_DCRP_STRT_DT - DCRP_CRE_DT > nn_due_date
then 1 else 0
end as grt_45_ct
Original query:
select wit_45_ct,grt_45_ct,
case when cnt = 1 and trim(to_char(new_due_date, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) in(‘MONDAY’,‘TUESDAY’,‘WEDNESDAY’,‘THURSDAY’) then new_due_date+1
when cnt = 1 and trim(to_char(new_due_date, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) = ‘FRIDAY’ then new_due_date+3
end as nn_due_date
from (
select a.DW_DX_DCRP_STRT_DT,
a.DW_DX_DCRP_STRT_DT+45 as actual_due_date,
to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’),
case when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) not in (‘SATURDAY’,‘SUNDAY’) then a.DW_DX_DCRP_STRT_DT+45
when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) =‘SATURDAY’ then a.DW_DX_DCRP_STRT_DT+47
when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) =‘SUNDAY’ then a.DW_DX_DCRP_STRT_DT+46
end as new_due_date,
(select count(1) from hldy where to_date(hldy_id,‘YYYYMMDD’) =
case when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) not in (‘SATURDAY’,‘SUNDAY’) then a.DW_DX_DCRP_STRT_DT+45
when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) =‘SATURDAY’ then a.DW_DX_DCRP_STRT_DT+47
when trim(to_char(a.DW_DX_DCRP_STRT_DT+45, ‘DAY’, ‘NLS_DATE_LANGUAGE=ENGLISH’)) =‘SUNDAY’ then a.DW_DX_DCRP_STRT_DT+46
end
)as cnt,
case when a.DW_DX_DCRP_STRT_DT - DCRP_CRE_DT <= nn_due_date
then 1 else 0
end as wit_45_ct,
case when a.DW_DX_DCRP_STRT_DT - DCRP_CRE_DT > nn_due_date
then 1 else 0
end as grt_45_ct
from dx_dcrp a, case_cnty c,csrt e,cnty d
)
vsenni (BOB member since 2015-11-10)