oracle - How do I create a conditional SQL query -


i trying create oracle sql query using if/else statements

if exists    (           select *             baninst1.an_employee_position            baninst1.an_employee_position.person_uid = 593791           ,    baninst1.an_employee_position.position_end_date null)    select *      baninst1.an_employee_position     baninst1.an_employee_position.person_uid = 593791    ,    (                  baninst1.an_employee_position.position_end_date null           or     baninst1.an_employee_position.position_end_date > sysdate)    ,    baninst1.an_employee_position.effective_start_date <= sysdate;else    select *      (                  select *                    baninst1.an_employee_position                   baninst1.an_employee_position.person_uid = 593791 )     rownum = 1;end if; 

however receive "unknown command" error when run it. no more error information

this may provide looking for:

select a.*   employee_position person_uid = 593791 , (       (a.position_end_date null)       or       (         a.position_end_date =         (select max(position_end_date)          employee_position b           b.person_uid = a.person_uid           , b.position_end_date not null         )       )     ) 

another way

select a.*   employee_position person_uid = 593791 , (       nvl(a.position_end_date, trunc(sysdate+100)) >=        (select max(position_end_date)        employee_position b        b.person_uid = a.person_uid        , b.position_end_date not null       )     ) 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -