Hello,
I have a select statement which reads from a table.
In the table there is flag. Based on the flag I decide
what action to take.
Basically I need to test if the flag is X then bring
all its records else if the flag is Y then test for another additional flag which should be equal to 100 and bring all of its records. Below I wrote the select with a union can it be written differently with a decode may be?? Or something else?
select a.orion_tank, b.OrionCrude, a.prop_modified_value,
a.DayInserted, SEQ5_CRDINV.nextval, sysdate, user
from ps_staging_data a, ps_crude_map b
where a.Orion_tank = b.OrionTank
and to_char(a.dayInserted,'dd/mm/yyyy') = to_char(sysdate, 'dd/mm/yyyy')
and a.validated = 1 and a.phd_confidence >= 100 and src_flag = 'PHD'
UNION
select a.orion_tank, b.OrionCrude, a.prop_modified_value,
a.DayInserted, SEQ5_CRDINV.nextval, sysdate, user
from ps_staging_data a, ps_crude_map b
where a.Orion_tank = b.OrionTank
and to_char(a.dayInserted,'dd/mm/yyyy') = to_char(sysdate, 'dd/mm/yyyy')
and a.validated = 1 and src_flag <> 'PHD';
I have a select statement which reads from a table.
In the table there is flag. Based on the flag I decide
what action to take.
Basically I need to test if the flag is X then bring
all its records else if the flag is Y then test for another additional flag which should be equal to 100 and bring all of its records. Below I wrote the select with a union can it be written differently with a decode may be?? Or something else?
select a.orion_tank, b.OrionCrude, a.prop_modified_value,
a.DayInserted, SEQ5_CRDINV.nextval, sysdate, user
from ps_staging_data a, ps_crude_map b
where a.Orion_tank = b.OrionTank
and to_char(a.dayInserted,'dd/mm/yyyy') = to_char(sysdate, 'dd/mm/yyyy')
and a.validated = 1 and a.phd_confidence >= 100 and src_flag = 'PHD'
UNION
select a.orion_tank, b.OrionCrude, a.prop_modified_value,
a.DayInserted, SEQ5_CRDINV.nextval, sysdate, user
from ps_staging_data a, ps_crude_map b
where a.Orion_tank = b.OrionTank
and to_char(a.dayInserted,'dd/mm/yyyy') = to_char(sysdate, 'dd/mm/yyyy')
and a.validated = 1 and src_flag <> 'PHD';