Filtering table via Query builder - null value not selecting all - google-app-maker

When my drop-down "filter" has no value selected, my table displays zero records. I need it to select all values.
The table is tied to Datasource1 containing fields:Name, Status, Team1, and Team2. I have a second Datasource called Teams that contains team names. I setup query builder for Datasource1 to change based on a radio button(status) and a dropdown(teamFilter).
Datasource1 - Query Builder:
status= :status and (team1 = :teamFilter or team2 = :teamFilter)
Selecting a value in the drop-down properly filters the table. The issue is when no value is selected, or if I select the null option.

Related

Apex Collection: how to have actual column names instead of C001, C002

created a page to allow users to input SQL statement, when user press button, it should Execute this query and another region with Classic Report will display results.
on Button a Dynamic Action execute PL/SQL code below:
on Click event:
begin
IF :P8_YOURSQL IS NOT NULL THEN
APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY (
p_collection_name => 'SOMECOLLECTION',
p_query => :P8_YOURSQL,
p_truncate_if_exists => 'YES'
);
end if;
end;
Item to Submit: P8_YOURSQL
second Action refreshes CR region and CR region is based on:
SELECT * FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SOMECOLLECTION';
resulted columns are not limited to the query results and column headers are C001, C002, C003 etc.
(a) how i can limit the columns to the SQL statement contained?
(b) how to change header to the actual column names?
(c) how to check for a valid SQL statement?
please help with sample code How To.
APEX_COLLECTIONS is a generic table so it has a couple of columns for the most common data types with names like C001, N001 etc. As with any table columns can be aliased in a query.
Example:
Create page process before header to populate the collection
APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY (
p_collection_name => 'EMP_COLLECTION',
p_query => q'!SELECT * FROM emp!',
p_truncate_if_exists => 'YES'
);
Run the page and open the "Session" window from the developer toolbar. Select "Collections" in the "View" dropdown and click "Set". This will list the data in the APEX_COLLECTIONS table for any collections that exist for the session. Take note of the data and the columns the data is in.
Leave the "Sessions" window open and create a sql query on the APEX_COLLECTIONS view with appropriate aliases.
SELECT
c001 as EMPNO,
c002 as ENAME,
c003 as JOB,
c004 as MGR,
<rest_of_columns>...
FROM
APEX_COLLECTIONS WHERE collection_name = 'EMP_COLLECTION'
It's not possible to alias columns when doing a SELECT * FROM ...
If the SELECT * is important then there is another possibility. Create a view on top of APEX_COLLECTIONS with relevant column names. Example:
CREATE OR REPLACE view EMP_COLLECTION_V
AS
SELECT
c001 as EMPNO,
c002 as ENAME,
c003 as JOB,
c004 as MGR
FROM
APEX_COLLECTIONS WHERE collection_name = 'EMP_COLLECTION'
and then use SELECT * FROM EMP_COLLECTION_V as SQL source for the classic report.
To get the columns names for a SELECT * FROM ... have a look at [DBMS_SQL.DESCRIBE_COLUMNS3][https://docs.oracle.com/en/database/oracle/oracle-database/18/arpls/DBMS_SQL.html#GUID-00AB5DE3-C428-4E60-9398-FD4892F32402]. There is an example in the doc that shows how to print the column names.
This can then be implemented in a classic report
Create a page item per column: P1_C1, P1_C2, etc
Set the column header for each column to the corresponding page item: col1 has header &P1_C1, col2 has header &P1_C2, etc
Create a page process to set the column headers based on the sql query using DBMS_SQL.DESCRIBE_COLUMNS3 - OR - use a
Note that it is strongly advised to assert the sql query to avoid unwanted sql (like a delete or drop table command).

Oracle Apex Select List LOV conditional query

I have an Editable Interactive Grid (for product_sale table) with a Select List (to select a product) in Oracle Apex 20.2 app.
Currently I'm using below query to populate this list of values.
SELECT productName,productId FROM product WHERE productAvailability = 'Y'
There are a few products that I need to set the productAvailability as 'N'. When I made this change, Interactive Grid of product_sale shows productId instead of the productName.
What I need to achieve is, only show products with productAvailability = 'Y' for new records (when going to add new record in to the table by clicking Add Row button) and for the old records show the productName of the selected product regardless the productAvailability.
Table Structure
Sample Data
Interactive Grid View
How could I achieve this?
You can achieve this using the "cascading list of values" option in the column settings. Let me illustrate with an example on the EMP sample table - you should be able to translate this to your own code:
Situation: BLAKE can not be selected as manager for any other employees than the one he is already manager for.
This would be the select:
SELECT ename, empno FROM emp WHERE ename != 'BLAKE'
As expected, for records that have BLAKE as manager, the MGR column will display the id because the value is not in the result set of the select list query. This is the behaviour you are seeing.
The solution has 2 steps:
Union the query with a query that has the value of the current row. I have rewritten the query using a CTE.
WITH all_mgr(dv, rv) AS
(SELECT ename, empno FROM emp WHERE ename != 'BLAKE'
UNION
SELECT m.ename, m.empno
FROM emp e
JOIN emp m ON e.mgr = m.empno
WHERE e.ename = :ENAME
)
SELECT dv, rv FROM all_mgr
Make sure column ename from the current row is bind to :ENAME. In "Cascading List Of Values" set both "Parent Column" and "Items to Submit" to ENAME. Now the select list will take the current row value for :ENAME and the list of values will include 'BLAKE' for users that have 'BLAKE' as a manager.

Return Records based on ID(search in textchanged event) column and (ISActive=true) column value(ASP.NET))

i am having a table Item(ItemId,ItemCode,ItemName,CategoryId,IsActive) columns.
i have a textbox for all columns.when i enter ItemId..in (txtItemId) textbox..all records based on that id should be filled in remaining textboxes for other columns.its working fine for itemid search.but my requirement is i want to filter only those records based on ItemId column with IsActive=1(true) i.e(filtering based on two columns).so,i want a query in ado.net (application level).The below query doesn't work.
strSqlCommand = "Select * from Item1 where ItemId=" + txtItemId.Text.Trim()" and IsActive="1";

How to get XML value from a column in SQL Server

I have a SQL Server table tblApplications with some columns... one of the columns is called Content and has XML values like in the following Image:
when i clicked on the value of content in the above image it displays like following in new tab
I want to get the value using id from the xml value of dataitem that is under the datagroupItem of datagroup as selected in following image, using query from the tblApplications
How to get the value from the content using id?? E.g. I want to get the value of id of dataitem = 'ForeNames'
How to get it using query????
You could try this query:
SELECT a.application_id,
x.y.query('.') AS DataItemNode,
x.y.value('(#type)[1]','NVARCHAR(50)') AS TypeAttr,
x.y.value('(#value)[1]','NVARCHAR(50)') AS ValueAttr
FROM dbo.tblApplications a
CROSS APPLY a.Content.nodes('/XmlDataPairDocument/dataitem/datagroup/datagroupitem/dataitem[#id="forenames"]') x(y)
or
DECLARE #id NVARCHAR(50);
SET #id='forenames';
SELECT a.application_id,
x.y.query('.') AS DataItemNode,
x.y.value('(#type)[1]','NVARCHAR(50)') AS TypeAttr,
x.y.value('(#value)[1]','NVARCHAR(50)') AS ValueAttr
FROM dbo.tblApplications a
CROSS APPLY a.Content.nodes('/XmlDataPairDocument/dataitem/datagroup/datagroupitem/dataitem[#id = sql:variable("#id")]') x(y)
Another similar questions-answers: here #1, here #2

Updateable Oracle SQL Report using Oracle ApEx 4.1

Basically, I have an SQL Updateable report based on the following sample SQL query:
select A, B, C from my_table;
Based on this report, I have made column B a SELECT LIST based on a Named LOV - I have also assigned this column an id of "lov_select"
Column C here is also a text area
My question and unsure how to do this, is, as this report can vary in rows, assuming this report returns 3 rows, based on the value selected from the Column B - select list, I want to use this value in column B select list to retrieve another value from a table and then return this value into Column C text are field, alongside this select list value used.
I would like to do this via a Dynamic Action.
For example:
Column A Column B (select list LOV) Column C
----------------------- ---------------------------- ------------------------------------
Row 1 NAME1 returns 5
Row 2 NAME2 returns 6
Row 3 NAME3 returns 7
So if I change row 2 Column B and select "NAME2", I then want to execute a query using the value "NAME2" which would return a value of 6, which I then would like populated alongsde NAME2 into Column C.
Manual tabular form with source:
select
apex_item.text(1, empno) empno,
apex_item.text(2, ename) ename,
apex_item.text(p_idx => 3, p_value => deptno, p_size => 4, p_maxlength => 2, p_attributes => 'class="deptno"') deptno,
apex_item.text(4, null) dname
from emp
2 possible solutions:
Dynamic action with ajax process
Event: Change
Selection Type: jQuery selector
jQuery selector: .deptno
Condition: no condition
True action: Execute javascript code
Fire on page load: unchecked
var lFetchFor = $(this.triggeringElement).val(),
lTarget = $(this.triggeringElement).closest('tr').find('input[name="f04"]');
$.post('wwv_flow.show',
{"p_request" : "APPLICATION_PROCESS=fetch_value",
"p_flow_id" : $v('pFlowId'),
"p_flow_step_id" : $v('pFlowStepId'),
"p_instance" : $v('pInstance'),
"x01" : lFetchFor},
function(data){
lTarget.val(data);
});
No affected element type
Dynamic actions only and hidden items
Event: Change
Selection Type: jQuery selector
jQuery selector: .deptno
Condition: no condition
True action: Set value
Set type: Javascript expression
Javascript expression: $(this.triggeringElement).val()
Fire on page load: unchecked
Affected elements:
Selection type: Item(s)
Item(s): P37_FIND_DEPTNO
True action: Set value
Set type: SQL statement
SQL Statement: select dname from dept where deptno = :P37_FIND_DEPTNO;
Page items to submit: P37_FIND_DEPTNO
Fire on page load: unchecked
Affected elements:
Selection type: Item(s)
Item(s): P37_FIND_DEPTNO_RESULT
True action: Execute javascript code
Code:
$(this.triggeringElement).closest('tr').find('input[name="f04"]').val($v ('P37_FIND_DEPTNO_RESULT'));
Fire on page load: unchecked
No affected element type
2 hidden items, value protected set to No
P37_FIND_DEPTNO
P37_FIND_DEPTNO_RESULT
Both take care of fetching the value, just depends on how you'd rather solve it.

Resources