Database Toolbox    

Building, Running, and Saving a Query

Topics covered in this section are:

Building and Running a Query

Build and run a query to import data from your database into MATLAB. Then save the query for use again later.

  1. Start the Visual Query Builder - see Starting and Quitting the Visual Query Builder.
  2. From the Data source list box, select the data source from which you want to import data. For this example, select dbtoolboxdemo, which is the data source for the tutorial database.

    The list includes all data sources you set up. If you do not see the data source you want to use, you need to add it - see Setting Up a Data Source in Chapter 1.

    After selecting a data source, the list of tables in that data source appears.

  1. From the Tables list box, select the table that contains the data you want to import. For this example, select salesVolume.

    After selecting a table, the fields (column names) in that table appear.

  1. From the Fields list box, select the fields containing the data you want to import. To select more than one field, hold down the Ctrl key or Shift key while selecting. For this example, select the fields StockNumber, January, February, and March.

    As you select items from the Fields list, the query appears in the SQL statement field.

  1. In the MATLAB workspace variable field, assign a name for the data returned by the query. For this example, use A.
  2. Click Execute to run the query and retrieve the data.

    The query runs, retrieves data, and stores it in a MATLAB cell array, which in this example is assigned to the variable A. In the Data area, information about the query result appears.

  1. Double-click A in the Data section. The contents of A is displayed in the Command Window. Another way to see the contents of A is to type A in the Command Window.

    As an example of how to read the results, sales for item 400876 are 3000 in January, 2400 in February, and 1500 in March.


 Starting and Quitting the Visual Query Builder NULL Values