Query connectivity tool provides tools for graphical constructing SQL query to AnyLogic Database. Query is the general SQL operation of retrieving data from database tables.
Using Query, you can feed up a model with data returned by the specified query. Query result represents a set of rows. Each row contains a set of values from the table’s columns you have specified in the query. You can use the query result to construct:
- Agent population. Each row of the query result will be used to add one more agent into a population. Values will be used to setup the parameters of the agent. This option is very useful in agent based modeling when you want to populate your model with agents, who have characteristics defined by parameters stored in some database.
- Collection. Each row of the query result will be used to add one more element to a collection. Values will be stored in the fields of the collection variable.
To define a query
- Drag the Query element from the Professional section of the Connectivity palette to the graphical editor.
- Open the Properties view and modify the Name of the element. This name will be used to identify and access this query.
- In the Database edit box, specify the database this query will access.
If you need to retrieve all data from some table of the specified database, just select the Select all from the table option in the Query section and specify the name of the table in the edit box to the right.
If you are working with Access 2007 database, specify the name of the table in the square brackets, e.g.: [Table].
- Otherwise, if you need to retrieve some specific data only, select the SQL option and type your custom query in the edit box below.
You can preview the query result any time.
To preview query results
- Select the Query object you want to examine.
- Go to the Properties view, Data feeding section.
- You will see the table listing the result this query will return. The table contains columns you have specified in the query.
Using the preview, you check the query. Table fields should match the ones defined in the query.
How can we improve this article?