Oracle APEX Change Where Clause in a Query According to a Page Item

87 views Asked by At

I have the P2011 form that contains a checbox item (P2011_All_Dpt_Employees) . This item Checked Value = 1 and UnChecked Value = 0.

Is it possible to change the WHERE part of a query based on these two values?

When P2011_All_Dpt_Employees = 1 then my query is:

    select count (e.ID) as Qty
from WORKING_SERVICES ws
    inner join EMPLOYEES e on e.WORKING_SERVICE = ws.ID
    inner join EMPLOYEE_WS_HISTORY eh on eh.EMPLOYEE_ID = e.ID and eh.WORKING_SERVICE = ws.ID
where e.EMP_STATUS = :P2011_EMPLOYEE_STATUS
and e.WORKING_SERVICE = :P2011_DPT_ID
and (:P2011_SEARCH is null
    or upper(e.LAST_NAME||' '||e.FIRST_NAME) like '%'||upper(:P2011_SEARCH)||'%'
    )
group by ws.ID, ws.WORKING_SERVICE
order by 1
FETCH FIRST 1 ROWS ONLY;

When P2011_All_Dpt_Employees = 0 then my query is:

select count (e.ID) as Qty
from WORKING_SERVICES ws
    inner join EMPLOYEES e on e.WORKING_SERVICE = ws.ID
    inner join EMPLOYEE_WS_HISTORY eh on eh.EMPLOYEE_ID = e.ID and eh.WORKING_SERVICE = ws.ID
where e.EMP_STATUS = :P2011_EMPLOYEE_STATUS
and (:P2011_SEARCH is null
    or upper(e.LAST_NAME||' '||e.FIRST_NAME) like '%'||upper(:P2011_SEARCH)||'%'
    );

I actually remove this where clause line: and e.WORKING_SERVICE = :P2011_DPT_ID

0

There are 0 answers