question

Gesa R avatar image
0 Likes"
Gesa R asked Mischa Spelt commented

Acess a Variable in a Query in FlexScript

Hi,

I have much information in global tabels (from Excel). For my simulation logic I need access to these data and sometimes sort it.

When I have FlexScript and make a query to create a new temporary table, can I include a variable like "i" or a token lable in the query?

Example:

  1. for (int i = 1; i<=10; i++)
  2. {
  3. Table result=Table.query("SELECT * FROM Customers \
  4. WHERE [Customer Group] = i) ;
  5.  
  6.  
  7. //Create items in a special queue dependant of i
  8. }

How can I access the data in an other way?

Thank you for helping.

FlexSim 18.0.3
global tableflexscriptquerysql queriesdata
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

Mischa Spelt avatar image
6 Likes"
Mischa Spelt answered Mischa Spelt commented
  1. Table result = Table.query("SELECT * FROM Customers \
  2. WHERE [Customer Group] = $1", i) ;

The syntax $n references the nth additional parameter to .query(). You can use it in the FROM, WHERE and ORDER clause, e.g. the above could also be rewritten as

  1. Table result = Table.query("SELECT * FROM $1 \
  2. WHERE [Customer Group] = $2", Table("Customers"), i);
· 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.