Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making My where Statement inside a Select branch!!

Status
Not open for further replies.

mozgheib

Programmer
Dec 14, 2003
50
KW
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';
 
Please try this :

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 >= DECODE ( src_flag,'PHD',100,a.phd_confidence )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top