question

Claire Krupp avatar image
0 Likes"
Claire Krupp asked Claire Krupp commented

GetValueByKey - more than one key?

The getValueByKey command is very useful (although the order of parameters seems backwards to me!), but often I have two keys.

I have been using a standard Table.query with parameters in those cases, but it would be nice to not have to do that - especially if I need to explain it to a customer or colleague who is not familiar with SQL and the $1 format. Any plans to expand this to use two (or more) keys? (Same for get RowByKey)

Thanks!

FlexSim 23.1.3
sqlgetvaluebykeygetrowbykey
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

·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Claire Krupp commented

You can add a column that combines two values into a key that you can then use with getValueByKey()

Just run something like this to create the key column with key value pairs:

Table.query("UPDATE GlobalTable1 SET Keys=ARRAY(Col1,Col2)");

then you can access the values using something like:

t.getValueByKey([2,"B"],4,"Keys");  //returns the value of col 4 by matching the value in the 'Keys' column with the array [2,"B]

getValueByKey_twoKeysInOneColumn.fsm

You could also consider creating a Map for your lookup rather than using a table.


· 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.

Claire Krupp avatar image Claire Krupp commented ·
Thanks @Jason Lightfoot that's a good idea.
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.