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 ?

  1. Table FromTable = ???
  2.  
  3. /*1)*/ Table Query = Table.query("SELECT * FROM Experiment.SC");
  4. /*2)*/ Table Query = Table.query("SELECT * FROM $1",FromTable);
  5. 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:

  1. 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:

  1. Object sc=Model.find("Tools/StatisticsCollectors/Staytime Collector");
  2. 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.

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Nicolas Mbz commented

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

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

It is very common that the table name needs brackets:

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

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

  1. 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():

  1. Table fromTable = Table("GlobalTable1");
  2. Table result = Table.query("SELECT $2 AS Col1, $3 AS Col2 FROM $1"
  3. , fromTable.numRows /*pass in the number of rows in your table*/
  4. , fromTable[$iter(1)][1] /*use $iter(1) to access the nth row*/
  5. , fromTable[$iter(1)][2]
  6. );
  7. 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.