question

IT Asset avatar image
0 Likes"
IT Asset asked Benjamin W2 commented

How do you use Table.query on a global list?

In the SQL Queries section of the user manual it mentions you can use a global list in a from statement. Can someone give me the correct syntax to do this?

Currently I have the following instead of the table query because I could not get the syntax quite right:

  1. string vsCell = "MED";
  2. string vsQuery = "WHERE lsCellName = \"" + vsCell + "\"";
  3. Array pullResult = List("glQbeforePress_MED").pull(vsQuery,0,0);

The goal of this was to find out how many of the tokens on the list with the label lsCellName = "MED".

Can anyone tell me what the equivalent to this would be with Table.query() ?

FlexSim 20.0.2
listlistssql
capture.png (15.8 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.

Manuel Sinco avatar image
1 Like"
Manuel Sinco answered Manuel Sinco edited

Hello @A Kamphaus,

You were close to the answer, but instead of inputting the Table name as a parameter, you can directly call it in the query, as you showed in the imaged you can do any query for any existing Table. This example may help you:

  1. List QbeforePress = List("glQbeforePress_MED");
  2. string CellName = "MED";
  3. Table ResultQ = Table.query("SELECT * FROM glQbeforePress_MED WHERE lsCellName
  4. = $1", CellName);
  5. int Counter = ResultQ.numRows;

The variable Counter will tell you how many tokens have the label "MED" as you wanted. If you want to check for another label, you just need to change the CellName variable value.

It's important to recall that you can, only, do queries for existing tables not memory tables that are created during a query like this one. However, you can use the memory table to search for information by looping through it, i.e. by looking for the tokens that apply and then pull them.

Hope it works, if you need any help, let me know.

Manuel.

5 |100000

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

Regan Blackett avatar image
1 Like"
Regan Blackett answered Regan Blackett edited

You could do this with just a regular Pull from List activity in process flow if you set your "Request" and "Require" values to zero and use the Query:

  1. WHERE IsCellName = "MED".

This will put all the Entries of the list that match the query into the token.pulled array but will leave the entries on the list. Then if you want to know many meet the criterial, you can use token.pulled.length.

· 5
5 |100000

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

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Joerg Vogel commented

I build my own global list in the attached model.

I check if I can get this list as a table queried.

  1. Table myTable = Table.query("SELECT * FROM myList");

Then I dump it to global.

  1. myTable.cloneTo(Table("dump"));

If I succeed I can start to count in another query.

  1. Table my2ndTable = Table.query(
  2. "SELECT COUNT(lsCellName) FROM myList WHERE lsCellName ='MED'"
  3. );

count-sql-entry-str.fsm


5 |100000

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