How to reference value from a drop down selection box ...? - database

I'm using Oracle APEX and I'm generating an interactive report .. Now I have a drop down selection box which has a list of values (LOVs) .. What I want to do is to use the currently selected value in the drop down box in the SQL query being used to generate the interactive report .. Like for example this is the SQL query for generating the interactive report to only show employees with rank Salesman:
select "EMP"."EMPNO" as "EMPNO",
"EMP"."ENAME" as "ENAME",
"EMP"."RANK" as "RANK",
from "EMP" "EMP"
where "EMP"."RANK" = 'SALESMAN'
The above query completely works for me ... Now I have a drop down box on the same page in APEX which is named RANKS, and has this LOV: SALESMAN, CLERK, ACCOUNTANT, DEPTHEAD
How do I change the SQL Query so that it now looks up the currently selected rank in the ranks drop down list and then only displays employees with that rank ...

If your ranks LOV is called P1_RANKS for example, then you can change the query SQL to:
select empno, ename, rank
from emp
where rank = :P1_RANKS
However, that only works once a rank has been selected. If you want to show all employees when no rank has been selected do this:
select empno, ename, rank
from emp
where (:P1_RANKS is null or rank = :P1_RANKS)
You can either make the select list submit the page to refresh the report or, preferably, create a dynamic action to refresh the report when the select list item is changed.

Related

Access to SQL Server - query results from a table as another tables query columns

I am taking user input from a series of combo boxes in a MS Access form, which might not all be chosen, so some will be "". But for the responses that are not "", I want to query those columns for the table the user has selected.
For example, this is my utopian solution which I'm I have no idea how to accomplish other than building a query for every possible combination and calling a procedure for that query:
SELECT **NON "" COMBOBOX CHOICES**
FROM T1
You can talk about the combobox field in the following syntax:
Forms![myForm]![myComboBox1Name]
The above returns the text from that box, either "" or a string they chose from the options. So in short, I was wondering if I inserted the valid non "" strings from those combo boxes into a table, then somehow used a SELECT statement on the table we could use the rows returned as the fields I want to query, example:
SELECT (SELECT * FROM ValidTable)
FROM T1
If the resource from the following link were successful, https://www.google.com/amp/s/blog.sqlauthority.com/2012/10/27/sql-server-storing-variable-values-in-temporary-array-or-temporary-list/amp/

How to find the most frequently occurring value in SSRS tablix dataset?

Consider following dataset that is displayed in tablix in SSRS report:
GroupID | ProductID
---------------------
Group 1 | Product1
Group 2 | Product10
Group 1 | Product2
Group 3 | Product27
Group 2 | Product12
Group 2 | Product14
I added new row via Insert Row/Outside Group - Below.
On this row I display total number of rows - achieved via CountRows(), number of distinct Groups - achieved via =CountDistinct(Fields!GroupID.Value)
I also want to display the name of the group with the most number of rows, in this case it would be "Group 2" (in case if there is more than one group with the same number of rows I only need to display one of them).
How can this be achieved? I think I should use some of aggregate or lookup functions but so far can't figure out how.
PS This report is being ported from Crystal Reports to SSRS. In Crystal Reports this is easily achieved via "Nth most frequent" summary with N=1 but there is nothing like this in SSRS as far as I can tell.
Add a tablix and set GroupId as Row Group.
For Rows Count use:
=Count(Fields!GroupID.Value)
Right click GroupID group in the Row Groups pane and go to group properties, in the Filters tab use the following settings:
For Expression use:
=Count(Fields!GroupID.Value)
It will filter the top 1 group with the greatest Rows count. The result is something like this:
UPDATE: The previous solution doesn't work if there is more than one group with the same number of occurencies.
Add a tablix, delete the details (default group) and add the GroupID field in the first column.
For the Rows Count column use the following expression replacing DataSetName by the actual name of your dataset:
=LookupSet(
Fields!GroupID.Value,
Fields!GroupID.Value,
Fields!GroupID.Value,
"DataSetName"
).Length
Right click your tablix and go to tablix properties, in the Sorting tab select Z to A order and use the previous expression in the Sort By textbox.
It should show the only one group even if a second group with same number of occurencies is present.
Let me know if this helps.

Oracle Apex: Add custom column into interactive report

I create a page and add an interactive report to show data of view
CREATE OR REPLACE VIEW FAC_FILE_MANAGEMENT_VIEW AS
SELECT FAC_FILE.NAME as FILE_NAME, FAC_NHAN_VIEN.USERNAME as USERNAME,
FAC_FILE_MANAGEMENT.FAC_MONTH as FAC_MONTH, FAC_FILE_MANAGEMENT.FAC_YEAR as FAC_YEAR, FAC_FILE_UPLOAD.LAST_UPDATED as LAST_UPDATED,
CASE IS_COMPLETED
WHEN 0 THEN 'Not Upload'
WHEN 1 THEN 'Completed'
END as IS_COMPLETED
FROM FAC_FILE_MANAGEMENT left join FAC_FILE on FAC_FILE_MANAGEMENT.FILE_ID = FAC_FILE.ID
left join FAC_FILE_UPLOAD on FAC_FILE_MANAGEMENT.FILE_UPLOAD_ID = FAC_FILE_UPLOAD.ID
left join FAC_NHAN_VIEN on FAC_FILE_MANAGEMENT.UPLOADED_BY = FAC_NHAN_VIEN.ID;
Now, I want to create new custom column nam 'View Detail'. This column is a link based on value of IS_COMPLETED
Completed: Show link to view detail
Not Upload: Blank
How can I add a custom column into interactive report?
Its much easier if you just add NULL to the query like this
SELECT NULL as View_Detail, <insert other columns>
FROM TABLE
add column to your report query like:
,DECODE(IS_COMPLETED,'Y','View Detail','N','') AS 'Detail'
This will add new column to your report.
Now go to your Report Attributes tab and edit Detail Column.
and change Display As to Standard Report Column.
Also, you need to select column in interactive report to display from your output.

JReport :Subreport query should filter based on sublink?

I am trying to create a report with subreport in it but I am getting error while executing sbreport query.
The main table shows the details of employee and subquery shows the detail of leaves for each month for each employee.
I have created a subquery where I am selecting all details from the table.
What my issue is:
When I am creating a subquery it should filter based on the sublink.
For example each row in the main report will represent an employee. If the sublink between main report and subreport is employee id, then the subquery should filter the detail based on the sublink.
i.e. if the subquery is
"select employee_id, noOfLeaves from Employee_Detail"
then while executing it should execute like
select employee_id, noOfLeaves from Employee_Detail where employee_id = 151 (where employee_id = 151 is the row from the main report)
Is there any setting in JDesigner where I can make the changes to get this.
I am using Version 10 JERntServer and JDesigner.
You should be able to right click on the subreport or embedded component and select Format Subreport or Link Properties and in the Field tab select the BandedObject in the Component edit box then select Field (Primary) = Field (Subreport) with employee_id of both reports. Be sure both reports contain employee_id.

Report Builder 3.0 Charts - Need to show empty category groups

I am using SQL Server Report Builder 3.0 to create a bar chart. The chart is a count of satisfaction scores (Excellent, Very Good, Good, Fair, Poor), with a bar showing each of the respective scores. It works beautifully, except in the case where there are no records with a specific score. I would like to be able to show all of the options, even if there is a value of zero. Is there a way to put a placeholder there or otherwise force it to show?
Create another table that contains all of the category names.
CREATE TABLE CATEGORIES(ID NOT NULL PRIMARY KEY);
Then insert the category names into the table.
INSERT INTO CATEGORIES
VALUES ('Excellent', 'Very Good', 'Good', 'Fair', 'Poor');
Then for your bar chart dataset,
SELECT C.ID, COUNT(A.ID)
FROM Categories C
LEFT OUTER JOIN yourTableNameHere A on C.ID = A.category
GROUP BY C.ID;
The result will be a dataset with (CategoryName, Count) records.

Resources