Am I correct in assuming that both Bank
and Machine
are integers in the DB table?
SELECT
ROW_NUMBER() OVER(ORDER BY Bank ASC) - 1 AS 'value',
[label],
Bank,
Machine
FROM(
SELECT
Bank,
Machine,
MAX(c.[label]) AS 'label'
FROM
Cycle_Records_IS p
CROSS APPLY (SELECT 'Bank' + convert(nvarchar, p.Bank) + '-Machine' + convert(nvarchar, p.Machine) as 'label') AS c
GROUP BY
Bank,
Machine
)t1
Should give you what is expected for the first dropdown. There is probably better/cleaner SQL to achieve this; personally I'd only run
SELECT
Bank,
Machine
FROM
Cycle_Records_IS
GROUP BY
Bank, Machine
and place the result somewhere and use a script to loop through it and create the dataset for the dropdown.
Have a named query of
SELECT
Serial AS 'value',
Serial AS 'label'
FROM
Cycle_Records_IS
WHERE
Bank = :bank
AND Machine = :machine
ORDER BY Serial DESC
as the binding for the options dataset of the serial number dropdown. The parameters of the named query binding would be
lookup({path.to.first.dropdown.options}, {first.dropdown.select.value}, Null, 'value', 'Bank')
and
lookup({path.to.first.dropdown.options}, {first.dropdown.select.value}, Null, 'value', 'Machine')
for bank
and machine
respectively.
To make everything easier on yourself, create 4 custom properties on the root container of the window called machineByBank
, selectedBankAndMachineIdx
, availableSerials
, and selectedSerial
.
Have the first query as the binding for machineByBank
, and bind the first dropdown's options dataset to this.
Bidirectionally bind the first dropdown's selectedValue
property to selectedBankAndMachineIdx
.
Bind the named query to availableSerials
, and bind the second dropdown's options dataset to this.
Bidirectionally bind the second dropdown's selectedValue
to selectedSerial