question

Saiprasad A avatar image
0 Likes"
Saiprasad A asked Saiprasad A commented

Could not parse Table.query() command

product_query.fsmI am trying to read specific values from a table using Table.query().
More specifically, in my attached flexsim model I am trying to read rack_idx column value of a specific product_variant_id from global table planogram.
But, the model shows an error that the query sentence could not be parsed.

Please help me in finding the issue in my model/code.
Thanks!

FlexSim 19.2.4
table.query
product-query.fsm (20.2 KiB)
· 2
5 |100000

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

Arun Kr avatar image Arun Kr commented ·
Table Temp = Table.query("SELECT * FROM planogram WHERE product_variant_id = $1" ,token.product_variant_id);

SQL query syntax is incorrect in your model. The label value on the token needs to be added as a parameter in the query. You need to update as mentioned above in the code.

1 Like 1 ·
Saiprasad A avatar image Saiprasad A Arun Kr commented ·
Thank you @Arun Kr. It resolved the issue I was facing.
0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Saiprasad A commented

The problem is that the field is a string so you need to either put the value in apostrophes to make it compare the actual value rather than look for a column with that name, or pass it in as a parameter as @Arun Kr mentions (this second option has been known to not work in some queries in some versions - so apostrophe wrapping may be the technique most certain to work in all versions).

Table Temp = Table.query("SELECT * FROM planogram WHERE product_variant_id = '"+ token.product_variant_id+"'");
· 3
5 |100000

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

Saiprasad A avatar image Saiprasad A commented ·
@Jason Lightfoot is there a significance to the comma before token.product_variant_id in your answer?
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Saiprasad A commented ·
Sorry - it's a mistake! Thanks I'll correct it.
0 Likes 0 ·
Saiprasad A avatar image Saiprasad A Jason Lightfoot ♦♦ commented ·
Okay. Thank you @Jason Lightfoot for the answer and the helpful information
0 Likes 0 ·