How can I add a conditional filter to a query? I have a dropdown on the page and I want to filter the report query based on dropdown selected value. I am fine with that part (just add the item name to the query preceded by a column), but the things is that I want the filter not to be added if nothing is selected in the dropdown. how can that be accomplished?
Update:
Example of the WHERE clause:
WHERE ID=5 AND START_DATE=SYSDATE-:P1_NUM_OF_DAYS
if P1:NUM_OF_DAYS has been selected and if not, the data should be selected for all the dates
I believe what you are looking for is a Function based report. This would allow you to include a PL/SQL function body that would return the query from the table/view and also apply any filters (if any) based on page items values. This is a very common use for classic reports when you want the end users to have the flexibility of applying filters on the report on the fly.
Code goes something like this:
Just make sure you have the page items' value stored in the session. You can do it by submitting the page or by doing a 'redirect and set value' if you do want wish to have another button like 'Apply Filter'. Also, have the appropriate value for 'source used' depending on how you want to have this implemented.
Hope this helps!
If that dropdown (Select List) item's name is P1_DEPTNO, then