question

Nicolas Mbz avatar image
0 Likes"
Nicolas Mbz asked Nicolas Mbz commented

How to query an Experiment.SC ?

How to passe an Experiment.StatisticCollector table as a parameter in a query ?

Table FromTable   = ??? 

/*1)*/ Table Query = Table.query("SELECT * FROM Experiment.SC");
/*2)*/ Table Query = Table.query("SELECT * FROM $1",FromTable);
Query.cloneTo(TableResult);
FlexSim 23.2.2
experimenterquerystatistic collector
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Nicolas Mbz commented

Something like this will work:

Table.query("SELECT * FROM Experiment.[Staytime Collector]").cloneTo(Table("GlobalTable1"))

You can just construct the string using the stats collector name - you don't need it as a parameter:

Object sc=Model.find("Tools/StatisticsCollectors/Staytime Collector");
Table.query("SELECT * FROM Experiment.["+ sc.name+"]").cloneTo(Table("GlobalTable1"));

You may want to join the taskid on the tasks and scenarios tables to get more useful fields.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Nicolas Mbz avatar image Nicolas Mbz commented ·
It was exactly my need, thanks a lot
0 Likes 0 ·
Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Nicolas Mbz commented

Option one is the correct way to query an experiment table:

/*1)*/ Table Query = Table.query("SELECT * FROM Experiment.SC");

It is very common that the table name needs brackets:

Table Query = Table.query("SELECT * FROM Experiment.[SC]");

It is usually unnecessary to pass the table as a parameter, as FlexSim supports nested queries:

SELECT ... FROM (SELECT a, b, c FROM Experiment.SC WHERE ...)

If you really need to query a custom data structure (which could include a table), you can use placeholders and $iter():

Table fromTable = Table("GlobalTable1");
Table result = Table.query("SELECT $2 AS Col1, $3 AS Col2 FROM $1"
    , fromTable.numRows         /*pass in the number of rows in your table*/
    , fromTable[$iter(1)][1]    /*use $iter(1) to access the nth row*/
    , fromTable[$iter(1)][2]
);
result.cloneTo(Table("GlobalTable2"));
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Nicolas Mbz avatar image Nicolas Mbz commented ·
Thanks a lot for the explanations ! I have to study this !
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.