How validate two select list in oracle apex - sql

I'm using Oracle apex, and i have 2 select list components that get the elements from the same table. i want build a currency converter, and the list of currency are "divisas"
My problem is: i want validate that when on one select component, one value is selected, the other component doesn't contain that element from select list 1. And vice verse
Also when on select 1 is null on the select 2 must show all result from the table, and vice verse.
I start with this query, but i can't do it works
select *
from divisas
where EN_APP = 'S'
and (
case when :P12_DIVISA is not null then (cod_divi <> :P12_DIVISA) else EN_APP = 'S' end
)
;
can somebody help me?

There's the Cascading List of Values property for Select List items. However, as you want to handle both items at the same time, you'll enter circular reference & dead loop so it won't just work.
Here's an option which does what you wanted; see if it helps:
create two items, e.g. P59_CURR_1 and P59_CURR_2 (for two currencies)
their type is Select List item
Page action on selection = "Redirect and set value"
SQL query looks like this (for P59_CURR_1)
select cod_divi d, cod_divi r
from divisas
where cod_divi <> nvl(:P59_CURR_2, 'X') -- would be `:P59_CURR_1` for another item
order by cod_divi
don't set cascading list of values parent item!
That's it; run the page and see how it behaves. Looks OK to me on apex.oracle.com's Apex 20.1 version.

Related

Apex Conditional Highlight with Data linked from another table

I have two separate table that store data in Apex. The main table that feeds the report is current employees. The other table I have is essentially a list of terminated employees with other information on it.
I am trying to find a way that if a name stored in both tables, that row would show up red on the report.
I put this code as an SQL Query into the report query:
select ID,
PAINT_SHOP,
"LOCKER_#",
LOCKER_LOCATION,
DEPT,
ASSOCIATE_NUMBER,
NAME__CINTAS_,
AUDIT_NOTES_,
LOCKER_TRANSFER_REQUESTED
from LOCKER_AUDIT
where (LOCKER_LOCATION = :P12_LL or :P12_LL is null)
select
NAME__CINTAS_,
case when LOCKER_TERM_LIST.NAME = 'TERMINATED' then 'salmon' else 'black' end as event_color
from Locker_Audit, LOCKER_TERM_LIST where LOCKER_AUDIT.NAME_CINTAS_ = LOCKER_TERM_LIST.NAME
*LOCKER_AUDIT --> Table for data storage of report
*LOCKER_TERM_LIST --> Table storing termed employee data
I am receiving this error:
Here is an option. Say this is your report query:
select x.*
,case when y.employee_status = 'TERMINATED' then 'salmon'
else 'black' end as event_color
from current_employees x, old_employees y
where y.employee_id = x.employee_id
Then from the content body, expand COLUMNS and look for the column you want to see in different color and click on it.
On the right frame you will see a text area called HTML Formatting.
Use some HTML there, like:
<span style="color:#EVENT_COLOR#">#YOUR_COLOURED_COLUMN#</span>
I think this would work.

SELECT name d , id r from ano where id != :P11_ANOID

I have a single page of master region with detail region. On both region I create the page item (SELCT LIST) of P11_ANOID and column in detail table ANOID (select list). Same list are used in bot page item and column but I want to filter the selected return id from P11_ANOID not present in the list of column. I used the query to filter in column list is
SELECT name d
, id r
from ano
where id != :P11_ANOID
but this can't work the. in this case the list cannot show for where condition? can anyone please help.?
If I understood you correctly, then P11_ANOID Select List item's value isn't "visible" to detail region's LoV query. Read: it isn't in the session state.
What to do? Change "Page action on selection" property for the P11_ANOID item to e.g. Submit or "Redirect and set value".

Multiple entries in crystal reportviewer after adding a SQL expression field

I am using Visual Studio 2017 and I installed the latest crystal reportviewer (22)
What I want is to click a button and create a report from the customer that is selected in the datagridview and the addresses that are shown in the second datagridview.
I managed to do all that but the problem is that a few fields contain numbers which need to be converted to text. An SQL query I would use to do this would be like:
SELECT c.customer_nr, c.status, s.rename FROM CUSTOMERS c INNER JOIN SETUP s on s.id = c.status WHERE s.afk = 'STA'
In my SETUP database I have the columns ID,AFK and RENAME so if the status would be 1 it would convert to text: "ACTIVE", if status = 2 it would convert to "INACTIVE" for example.
I could do something with a formula field like this:
IF ({c.status} = 1) THEN "ACTIVE" ELSE
IF ({c.status}) = 2 THEN "INACTIVE"
but that is not good because i could add another status or change the name in the database etc.
So then I tried with an SQL expression field and I put something like this:
(
SELECT "SETUP"."RENAME" FROM SETUP
WHERE "SETUP"."AFK" = 'STA' AND "SETUP"."ID" = "CUSTOMERS"."STATUS"
)
There must be something wrong because I get the correct conversion but there is only one address in the database but I get 7 pages all with the same address. There should only be one address like I get when I remove the SQL expression field. Where does it go wrong?
* EDIT *
I found the problem. When I create a new database that contains only unique id's then it works. In my original database I have multiple times the id's 1,2,3,4,5 but with different abbreviations in column AFK. Somehow the query looks for the id value and every time it finds this id no matter the AFK value it generates an entry for the address value.
Maybe in the future I will find out how this exactly works for now I have a workaround.
Create a new table for example CrRepSta and add the following entries:
ID,AFK,RENAME
1,STA,Active
2,STA,Inactive
etc
The new query:
(
SELECT "CrRepSta"."RENAME" FROM CrRepSta
WHERE "CrRepSta"."AFK" = 'STA' AND "CrRepSta"."ID" = "CUSTOMERS"."STATUS"
)
And by the way the statement "CrRepSta"."AFK" = 'STA' is not really needed.

Access 2013 ComboBox value based on other ComboBox with Junction Table

Good day. This is a follow-up to a previous question. I have a form with 2 comboboxes where the 2nd one depends on the value in the 1st one. I have the code to show the drop down list in the 2nd combobox but I am unable to select anything but the first entry.
Table 1: name - Supply_Sources, fields - Source_ID(pk), SupplySourceName
Table 2: name - Warehouse_Locations, fields - WLocation_ID(pk), Location_Name
Table 3 (junction): name - SupplySource_WarehouseLocation, fields - Supply_Source_ID(pk), Location_In_ID(pk)
On my form 'frmInventoryReceivedInput' I have cboSupplySource and cboWLocation. I populate cboSupplySource with
SELECT [Supply_Sources].[Source_ID], [Supply_Sources].[SupplySourceName]
FROM Supply_Sources;
The SQL for cboWLocation is:
SELECT SupplySource_WarehouseLocation.Supply_Source_ID,
Warehouse_Locations.Location_Name FROM Warehouse_Locations
INNER JOIN (Supply_Sources INNER JOIN SupplySource_WarehouseLocation
ON Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID)
ON Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE ((( SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
There are 3 options for me in the cboWLocation drop down list (based on cboSupplySource). However, it doesn't matter which one I choose, it defaults to the first one. What do I need to do to be able to choose the other options?
I recreated it and it works OK, the only thing I did differently was create a query with the SQL:
SELECT
SupplySource_WarehouseLocation.Supply_Source_ID, Warehouse_Locations.Location_Name
FROM
Warehouse_Locations INNER JOIN
(Supply_Sources INNER JOIN
SupplySource_WarehouseLocation ON
Supply_Sources.Source_ID = SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID = SupplySource_WarehouseLocation.Location_In_ID
WHERE
(((SupplySource_WarehouseLocation.Supply_Source_ID)=
[forms]![frmInventoryReceivedInput]![cboSupplySource]));
so I could check that part separately from the UI.
For cboWLocation, I have column widths 0";1", rowSource qry_cbo2, and bound column 2. Try changing your bound column from 1 to 2 and see if that helps.
-Beth

SQL Join based on a pattern

I have two tables tmpModels and tmp_product. Need to find matching models based on the model in tmpModel.
For example, If tmpmodel.updatedmodel ='amb3771' and tmp_product.updatedmodel could be 'amb3771bian' or '123abc3771xv' then we have a match.
Meaning that the tmp_product.updatedmodel should contain a matching pattern from tmpmodel anywhere in the updatedmodel column.
I have actually created a stored procedure but here is a snippet checking the behaviour for one particular value.
declare #model1 nvarchar(255)
set #model1 = 'amb3771'
select g.updatedmodel as GFK,p.updatedmodel Product from dbo.tmpModels g
join dbo.tmp_product p
on g.updatedmodel= substring(p.updatedmodel,PATINDEX('%#model1%',p.updatedmodel),LEN(#model1))
select #model1
I am expecting only two rows to be shown in the result. I don't understand why a different value is being assigned to #model1 even though I am forcing it to 'amb3771' and strangely there is no result matching 'amb3771'!! Please help me understand why this logic doesn't work and give the desired result. Below is the result -
GFK Product
w679 w679
t754cw t754cw
wa5714 wa5714silber
fl2823 fl2823
dc7230 dc7230
wda100 wda100
wa74sd wa74sd
ev9547 ev9547
wa5714 wa5714weiss
wa7439 wa7439
wda210 wda210wpm
wda210 wda210wpm
w194 w194
wda110 wda110wcs
wa5714 wa5714silber
wda100 wda100
First of all as DLeh mentioned #model should not be in quotes.
I don't understand why a different value is being assigned to #model1
even though I am forcing it
No different value is assigned to #model
If you execute query below you can see PATINDEX is returning 0 and then substring is getting full value of p.UpdateModel from 0th index to its length
select g.updatedmodel as GFK,p.updatedmodel Product, PATINDEX(#model1,p.updatedmodel)
from dbo.tmpModels g
join dbo.tmp_product p
on g.updatedmodel= substring(p.updatedmodel,PATINDEX(#model1,p.updatedmodel),LEN(#model1))
One solution I can suggest is to use WHERE condition instead of JOIN
set #model1 = '%wa5714%'
select DISTINCT g.updatedmodel as GFK,p.updatedmodel Product
from dbo.tmpModels g
, dbo.tmp_product p
WHERE PATINDEX(#model1,p.updatedmodel) > 0
AND PATINDEX(#model1,g.updatedmodel) > 0
I am assuming your model should display values of tmpModel and tmp_Product.
If you have different requirement the provide more details/example