Select Query run Entire Dropdown list

Have a query developed by the original programmer which woks just fine. Is there a way to get this query to go through the entire dropdown list? I tried different ways of replacing the “selectedLabel” portio with “data” believing this might use the entire data set, but i get swamped with errors.
Here is the current query:

SELECT A.Status AS 'Fault Code', C.faultdef AS 'Fault Description', A.t_stamp AS 'Start Time', B.t_stamp 'End Time', TIMESTAMPDIFF(Second,A.t_stamp,B.t_stamp) AS 'Seconds' FROM {Root Container.Dropdown.selectedLabel}_Status A INNER JOIN {Root Container.Dropdown.selectedLabel}_Status B ON B.{Root Container.Dropdown.selectedLabel}_status_ndx = (A.{Root Container.Dropdown.selectedLabel}_status_ndx + 1) INNER JOIN Fault_Definitions C ON C.faultcode = A.Status WHERE (C.machinecode = {Root Container.Dropdown.selectedValue}) AND A.Status > 0 AND A.t_stamp >= '{Root Container.CalendarStart.formattedDate}' AND A.t_stamp <= '{Root Container.CalendarEnd.formattedDate}' ORDER BY A.{Root Container.Dropdown.selectedLabel}_status_ndx ASC;
Thanks ahead of time for any assistance

There are various ways this could be done. A quick way would be to replace the Dropdown expressions with hardcoded table names and values and use multiple queries and combine them with UNIONs.

A more general solution could be implemented by generating the query with some scripting. For example a script could generate a query using the table names and values that exist in the Dropdown data property.

Here’s the query converted to using hardcoded table names and values and combined using UNIONs:

(SELECT A.Status AS 'Fault Code', C.faultdef AS 'Fault Description',
A.t_stamp AS 'Start Time', B.t_stamp 'End Time', TIMESTAMPDIFF(Second,A.t_stamp,B.t_stamp) AS 'Seconds'
FROM Table1_Status A
INNER JOIN Table1_Status B ON B.Table1_status_ndx =
(A.Table1_status_ndx + 1)
INNER JOIN Fault_Definitions C ON C.faultcode = A.Status
WHERE (C.machinecode = 1) AND A.Status > 0
AND A.t_stamp >= '{Root Container.CalendarStart.formattedDate}' AND A.t_stamp <= '{Root Container.CalendarEnd.formattedDate}'
ORDER BY A.Table1_status_ndx ASC)
UNION
(SELECT A.Status AS 'Fault Code', C.faultdef AS 'Fault Description',
A.t_stamp AS 'Start Time', B.t_stamp 'End Time', TIMESTAMPDIFF(Second,A.t_stamp,B.t_stamp) AS 'Seconds'
FROM Table2_Status A
INNER JOIN Table2_Status B ON B.Table2_status_ndx =
(A.Table2_status_ndx + 1)
INNER JOIN Fault_Definitions C ON C.faultcode = A.Status
WHERE (C.machinecode = 2) AND A.Status > 0
AND A.t_stamp >= '{Root Container.CalendarStart.formattedDate}' AND A.t_stamp <= '{Root Container.CalendarEnd.formattedDate}'
ORDER BY A.Table2_status_ndx ASC)
UNION
(SELECT A.Status AS 'Fault Code', C.faultdef AS 'Fault Description',
A.t_stamp AS 'Start Time', B.t_stamp 'End Time', TIMESTAMPDIFF(Second,A.t_stamp,B.t_stamp) AS 'Seconds'
FROM Table3_Status A
INNER JOIN Table3_Status B ON B.Table3_status_ndx =
(A.Table3_status_ndx + 1)
INNER JOIN Fault_Definitions C ON C.faultcode = A.Status
WHERE (C.machinecode = 3) AND A.Status > 0
AND A.t_stamp >= '{Root Container.CalendarStart.formattedDate}' AND A.t_stamp <= '{Root Container.CalendarEnd.formattedDate}'
ORDER BY A.Table3_status_ndx ASC)
UNION ...

I haven’t tried out this solution so I’m not sure if there is any problem with it.

:prayer: EXCELLENT! Once I paid attention to the syntax changes all was EXCELLENT!

U-Rule! Thanks!