question

Sebastian Hemmann avatar image
1 Like"
Sebastian Hemmann asked Brandon Peterson edited

Problem with getquerymatchtablerow()

The attached example model shows a user-command ("command1") with this query:

query("SELECT MAX(Prio) FROM GlobalTable1");

The greatest value of the column "Prio" is searched in GlobalTable1 and this works fine.

But getquerymatchtablerow("GlobalTable1", 1); does not return the row 1 where the value is in row 1.

I can´t find out why but it seems as the number of rows in GlobalTable1 is returned?

FlexSim 16.0.1
flexsim commandsglobal tablequeryuser commandscripting
beispiel.fsm (12.9 KiB)
5 |100000

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

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo edited

It turns our that the command getquerymatchtablerow() is working as designed. We will update the documentation to explain this more clearly.

Because you have an aggregation function (MAX), the query can't determine what row you are asking about. For example, if you executed the query below, it would find values from two different rows:

query("SELECT MAX(Prio), MIN(Nr) FROM GlobalTable1");

A better way to handle this query is:

query("SELECT Prio FROM GlobalTable1 ORDER BY Prio DESC LIMIT 1");
return getquerymatchtablerow(1,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.

Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo edited

This looks like a bug with that command. I'll add a note to the development list.

For now, you could store the row number in a column (like you are in this example) and return that value from the query:

query("SELECT Nr, Prio FROM GlobalTable1 ORDER BY Prio DESC LIMIT 1");

Attached is a sample model showing this method.


5 |100000

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

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.