STEM help / Exchanging data

6.6.4 Importing a single number from a database

If you want to refer to data in another STEM model, the easiest way is to open the other model in the Editor, then click with the mouse to pick up the external reference, just as you would for an internal reference.

For a database, you must type the <reference> text into a formula by hand, but you can use the External Links dialog to format the filename part correctly.

For example, suppose you want to import a Capital Cost from a Microsoft Access database, c:\data\costs.mdb, using a SQL query, SELECT Value from CostTable WHERE Name='Transceiver':

  1. Select Costs from the Resource icon menu. The Costs dialog appears.
  2. Select the Capital Cost field with the mouse or cursor keys.
  3. Select Links… from the File menu on the main Editor window. The External Links dialog is displayed.
  4. Select the Add… button to display the Define External Link dialog.
  5. Enter c:\data\costs.mdb and click OK. The file is added to the list of Links in the External Links dialog.
  6. Select the Paste button to enter the <filename>! part of an external reference into the formula bar for Capital Cost: 'C:\DATA\COSTS.MDB'!.

Pasting a filename from the External Links dialog

  1. Now type the <reference> part, "SELECT Value from CostTable WHERE Name='Transceiver' ", including the quotes, to complete the formula.

Note: If you prefer to browse for the required file, you can click the Browse… button on the Define External Link dialog to display the Select External File dialog, a standard Windows file-selection dialog.

When importing a single number from a database like this, the SQL query used should just return a single number.

It is also possible to retrieve time-series data or default values for a whole model element from an appropriately formatted database – see 4.14 Using default, set and frozen values. In this case, a SQL query can return many rows. Extra columns in the query qualify where each value should go, as described in the following pages.

 

© Implied Logic Limited