article

Paul Toone avatar image
0 Likes"
Paul Toone posted

SQL Queries Concepts   

FlexSim provides a flexible method for querying, filtering and prioritizing data in a model using the SQL language. Using SQL queries, users can do standard SQL-like tasks, such as searching one or more tables in FlexSim to find data that matches criteria as well as prioritizing that data. Instead of using FlexScript code to manually loop through and sort table data, you can write a single SQL query using the query() command to do all the work for you.

For example, let's say you have a global table in your model that looks like the following:

And let's say you want to search that table to find the name and id of the customer with the most total orders. The manual method for doing this in FlexScript would look like the following:

treenode customers = reftable("Customers");  int bestRow = 0;  int highestTotalOrders = 0;  for (int i = 1; i  highestTotalOrders) {          bestRow = i;          highestTotalOrders = totalOrders;      }  }

Alternatively, using SQL and FlexSim's query() command, you can do it much more simply, as follows:

query("SELECT CustomerId, Name FROM Customers /  ORDER BY [Total Orders] DESC LIMIT 1");  int bestCustomerId = getqueryvalue(1, "CustomerId");  string bestCustomerName = getqueryvalue(1, "Name");

This is a pretty simple example. More complex tasks such as sorting multiple results or searching multiple tables would be much more complex to perform manually in FlexScript, whereas doing those complex searches using SQL is relatively easy once you understand the rules of SQL and how to write SQL queries.

FlexSim's SQL functionality also includes advanced querying techniques. These allow you to do searches on data in the model that are not  structured like standard tables. You can search flow items, task sequences, resources, really any data in a model that can be conceptualized into lists.



flexsim users manual
5 |100000

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

Article

Contributors

paul.t contributed to this article

Navigation

FlexSim 2016.1