How to do a SQL Query from the Arrivals Table ?

How to do a SQL Query from the Arrivals Table ?

leah_r
Not applicable
20 Views
1 Reply
Message 1 of 2

How to do a SQL Query from the Arrivals Table ?

leah_r
Not applicable

[ FlexSim 23.2.1 ]

Hello !

I want to create a user command that query the patient source arrival of my model.

I tried running this code in the script console:

// OPTION 1
// Table tableArrivals = Model.find("Tools/ProcessFlow/Arrivals/Source>variables/arrivals");
// Table table = Table.query("SELECT SUM(D_discProv_cleanup) FROM tableArrivals WHERE id_salle = 1 AND perf_caseRank > 3"); // OPTION 2 Table table = Table.query("SELECT SUM(D_discProv_cleanup) FROM TableArrivalsSaved WHERE id_salle = 1 AND perf_caseRank > 3"); // RESULT double value = table[1][1]; return value;

Using the first two rows (option 1) resulted in the following error:

exception: FlexScript exception: No resolved tables at <no path> c: <no path> i: <no path>

Using the option 2 allowed me to obtain the expected value.

My questions are the following:

1) Is it necessary to clone the arrival table to query it?

2) Is there an easier way to get the sum value without passing by "table[1][1]" ? I tried returning the query directly and it does not work as it is in the form of a Table.

1696078711477.png


Thanks in advance,

Leah


0 Likes
Accepted solutions (1)
21 Views
1 Reply
Reply (1)
Message 2 of 2

moehlmann_fe
Observer
Observer
Accepted solution

The only things you can query directly by name are, to my knowledge, global tables, global lists, statistisc collector tables, and calculated tables. You can however pass in any node that contains table data (either as a bundle or through subnodes) into the query as a parameter.

See the section "Table Selection" in the documentation.

You can also read the result directly without assigning it to a variable first.

Table tableArrivals = Model.find("Tools/ProcessFlow/Arrivals/Source>variables/arrivals"); return Table.query("SELECT SUM(D_discProv_cleanup) FROM $1 WHERE id_salle = 1 AND perf_caseRank > 3", tableArrivals)[1][1];