How to query an Experiment.SC ?

How to query an Experiment.SC ?

nicolas_membrez4BM5L
Enthusiast Enthusiast
162 Views
4 Replies
Message 1 of 5

How to query an Experiment.SC ?

nicolas_membrez4BM5L
Enthusiast
Enthusiast

[ FlexSim 23.2.2 ]

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);
0 Likes
Accepted solutions (1)
163 Views
4 Replies
Replies (4)
Message 2 of 5

jason_lightfoot_adsk
Autodesk
Autodesk
Accepted solution

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.

0 Likes
Message 3 of 5

JordanLJohnson
Autodesk
Autodesk

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"));
.


Jordan Johnson
Principal Software Engineer
>

0 Likes
Message 4 of 5

nicolas_membrez4BM5L
Enthusiast
Enthusiast
It was exactly my need, thanks a lot
0 Likes
Message 5 of 5

nicolas_membrez4BM5L
Enthusiast
Enthusiast
Thanks a lot for the explanations ! I have to study this !
0 Likes