question

Rob Davies avatar image
0 Likes"
Rob Davies asked Logan Gold answered

How do I look up a value in a global table?

As a SQL statement, I would write: "SELECT HCPType FROM TreatmentFormulary WHERE TXID = 3". (note: TXID does not equal row). I will then use the result to decide what the next activity is in my treatment track. How do I get that HCPType value ???

FlexSim HC 5.1.0
global table
5 |100000

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

1 Answer

·
Logan Gold avatar image
2 Likes"
Logan Gold answered

After using the query() command, you usually use the getqueryvalue() command to retrieve a specific result from that query. Since the query() command can return more than one result, you treat those results like a table. The getqueryvalue() command takes two parameters, the row and column in the results table that contains the value you want to retrieve.

It sounds like you are only expecting one value back from the query, so you can treat the results table like it only has one row and one column. Please adjust your code or let me know if that is not the case. That means to retrieve the value, you would probably want to do something like this:

double hcptypeValue = getqueryvalue(1, 1);

Then you can use the hcptypevalue variable (or whatever you name it) in the rest of your logic to determine the next activity. You'll want to change the variable to be a string if the HCPType column in the TreatmentFormulary table is actually holding string data and not number data.

You could also forgo the variable and just use a return statement to directly return the value from the results table, depending on where you are using the getqueryvalue() command. However, I would need to know more information about the model and probably see the model to know exactly.

One final note about the getqueryvalue() command. In my example, the column parameter is using a number since I am assuming we only have one column in the results table and this way is marginally more straightforward. However, it is also possible to use a string and query a specific column name in the results table. The command would look like:

double hcptypeValue = getqueryvalue(1, "HCPType");

This is helpful if the results table contains multiple columns. It's also possible to rename of column in the results table through the query() command, so you would use that new name as the second parameter if that is the case.

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.