

We’re embedding Part within another function called Table which will build us a table which will be used to graph the values. To extract this information, one must reference the table (we called the table, “query”) and then address the part of the table by using Part. The pertinent value for the list to graph is the numerical value of each of the sub-tables within the main table. The table created by SQLExecute is actually a table of tables. The first parameter that BarChart expects is a list of values.

One of those reasons is that we’ve created lists within the function. If one looks at the documentation for BarChart, this example does not appear to follow the same rules at first glance. Once the results from the database have been returned, we can pass them to the BarChart function. Next, build the query as described above using the SQLExecute function like so: So when we build our query in Mathematica, we’ll just use, “SELECT Name, SalesLastYear FROM Sales.SalesTerritory”.Īs described in a previous post, make sure to import DatabaseLink and set up your database connection to SQL Server.

The target table for this example is one that has easy to graph data: Sales.SalesTerritory. For the purposes of this example, we’re going to pull a basic select query from the AdventureWorks database and graph it. To build a bar chart in Mathematica, the function we would use is BarChart. In this post, we’re going to build a basic bar chart that extracts data from a simple query in SQL Server.
