Oracle Apex: Add custom column into interactive report - database

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.

Related

Delete row operation in Microsoft Access

The picture is a snap shop of the query that i want to work on.
1. I want to delete any row that has blank W field together with all other row that share the same product_code field. for example, from the picture, 103346 has a blank W field, therefore any row with 103346 should be deleted (even if its field W is not blank).
I want to be able to export the new query to excel (If Possible).
I dont mind if this is through SQL or VBA code.
I am new to MS Access
One way of doing this using SQL is:
Create the query, and add the table (I've called mine ProductData);
Select the fields you want in the output;
In the criteria field for PRODUCT_CODE, type:
Not In (SELECT product_code FROM ProductData WHERE W IS NULL)
The SQL should like this:
SELECT ProductData.PRODUCT_CODE, ProductData.PURE_QP1, ProductData.W
FROM ProductData
WHERE ProductData.PRODUCT_CODE NOT IN (SELECT product_code FROM ProductData WHERE W IS NULL);
And to export this to Excel, the VBA code would be:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Query3", "J:\downloads\test.xlsx", True
Where Query3 is the name of the query that you have created.
Regards,
You can do it with EXISTS:
DELETE FROM tablename AS t
WHERE EXISTS (
SELECT 1 FROM tablename
WHERE PRODUCT_CODE = t.PRODUCT_CODE AND W IS NULL
)
To delete all empty records in a Microsoft Access table. You can use:
DoCmd.RunSQL "DELETE * FROM TableName WHERE FieldName='';"
There's more delete commands at the link here

SQL server : Inserting/updating missing data from one table to another

I have two table "Container" and "Control". These are existing tables and there is no foreign key relationship between the two. These are also very old tables so are not normalized. And I cannot change the structure now.
Below is the structure of the two tables.
Container table :
Control Table :
The Name field in Control table contains CTableName+CPName from Container table.
I want to update the columnName field of Control table with the value of CID column of Container table. and also want to insert one more record (for ctable2 i.e the fourth row in final Control table below) in Control table.
The tablename and columnname columns have will always be have default values.
The final Control table should look like this:
How do I do this?
I hope you want to apply this fix because you want normalize your table structure.
Try this:
First step:
In this way you'll UPDATE all Control rows with the value of Container table where the couple fields CTableName and CPName are the same of Name (excluding the rows of Container with the same couple fields)
UPDATE Control
SET ColumnValue = (
SELECT c.CID
FROM Container c
WHERE c.CTableName + '+' + c.CPName = Control.Name
AND NOT EXISTS(
SELECT 'PREVIOUS'
FROM Container c2
WHERE c.CTableName = c2.CTableName
AND c.CPName = c2.CPName
AND c.CID < c2.CID
)
),
TableName = 'default', ColumnName = 'default'
WHERE ColumnValue IS NULL
Second step:
Adding elements don't present in Control table
INSERT INTO Control (field list)
SELECT field list
FROM Container co
WHERE NOT EXISTS(
SELECT 'in_control'
FROM Control ct
WHERE co.CID = ct.ColumnValue
)
After these two steps you can drop column Name in Control table
I am an Oracle plsql programmer and worked with Sql-server as well.
First you should describe the relationship between the 2 tables, in the end i could figger it out but it's better you explain it yourself.
To update a table with information from another table you should ask yourself:
- when should the update take place?
- what are the conditions to start the update?
- how should the update be done?
In Oracle there is a database object called a trigger. It's quite a handy object and probably just what you need. I believe that sql-server has it too.
Pls fee free to ask any questions but do read the sql-server appropriate manual as well.
Good luck, Edward.

View showing incorrect data

I have a very simple database. It contains 3 tables. The first is the primary input table where values go in. The 2nd and 3rd are there purely for translating values to names for a view. When I view the rows in table 1, I can see that column businessUnit contains valid values in all rows. When I add the Business_Units table (The 3rd table in this DB), all but 2 rows go away and despite the businessUnit value both being 1 in the 1st table, the view gives them different names.
I created a DB diagram and uploaded a screenshot to imgur. Link: http://imgur.com/jXF7L1R
I only have 2 relationships in the table. One from equipType on New_Equipment_User to id in Equipment_Type and one from businessUnit in New_Equipment_User to id in Business_Units. The weird thing is that the Equipment Type works perfectly, yet when I replicate the table, relationship and view information exactly, it doesn't work. Instead of 6 rows appearing, there are only 2 which share the same value in businessUnit, but gives 2 different names for it.
In case it matters, here is my view Query:
SELECT dbo.New_Equipment_User.id, dbo.Equipment_Type.name AS equipType, dbo.New_Equipment_User.jobNumber, dbo.New_Equipment_User.costCode,
dbo.New_Equipment_User.reason, dbo.New_Equipment_User.mobile, dbo.New_Equipment_User.mobileQty, dbo.New_Equipment_User.mobileComment,
dbo.New_Equipment_User.laptop, dbo.New_Equipment_User.laptopQty, dbo.New_Equipment_User.laptopComment, dbo.New_Equipment_User.desktop,
dbo.New_Equipment_User.desktopQty, dbo.New_Equipment_User.desktopComment, dbo.New_Equipment_User.modem, dbo.New_Equipment_User.modemQty,
dbo.New_Equipment_User.modemComment, dbo.New_Equipment_User.printer, dbo.New_Equipment_User.printerQty, dbo.New_Equipment_User.printerComment,
dbo.New_Equipment_User.camera, dbo.New_Equipment_User.cameraQty, dbo.New_Equipment_User.cameraComment, dbo.New_Equipment_User.dateRequired,
dbo.New_Equipment_User.requestedBy, dbo.New_Equipment_User.dateRequested, dbo.New_Equipment_User.approvalStatus,
dbo.Business_Units.name AS businessUnit
FROM dbo.New_Equipment_User
JOIN dbo.Equipment_Type ON dbo.New_Equipment_User.equipType = dbo.Equipment_Type.id
JOIN dbo.Business_Units ON dbo.New_Equipment_User.id = dbo.Business_Units.id
WHERE (dbo.New_Equipment_User.approvalStatus = '0')
And here is an image of the view since it is easier to read: http://imgur.com/pZ97ehQ
Is anyone able to assist with why this might be happening?
Try using a LEFT JOIN
SELECT ...
FROM dbo.New_Equipment_User
JOIN dbo.Equipment_Type ON dbo.New_Equipment_User.equipType = dbo.Equipment_Type.id
LEFT JOIN dbo.Business_Units ON dbo.New_Equipment_User.id = dbo.Business_Units.id
This will ensure that all dbo.New_Equipment_User and all dbo.Equipment_Type is present

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.

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

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.

Resources