MS Access for the Business Environment: Access Query Techniques: Crosstab Queries - Page 3

November 3, 2003

We will now move to SQL view, as we wish to use direct SQL and to work with queries at a level that goes beyond working with wizards, or even the Design view we have used in the past.

11.  Select SQL View using the View Selector button in the main toolbar (it appears under the File item on the main menu), as shown in Illustration 6.

Illustration 6: Select SQL View

The SQL view editor appears, complete with a SELECT keyword in place, followed by the ubiquitous ending character for MS Access queries, the semicolon (";"). Illustration 7 depicts the initial view.

Illustration 7: Initial SQL View

Here we can enter, display, and / or modify a query using SQL directly, as we will throughout this lesson. (We can do many things here that might prove difficult or impossible in Design view, or under the auspices of wizardry. We want to see the actual SQL for a crosstab in the present example, and the powerful flexibilities it affords us.)

We will compose a simple SELECT query to gain an understanding of our fundamental dataset; our query will focus on the customer and product information, with the appropriate joins to create relationships between various tables in the Northwind database.

12.  Type the following basic SELECT query into the editor:


   Customers.CompanyName, Categories.CategoryName, 

     Count(Products.ProductID) AS Qty

     INNER JOIN Products ON Categories.CategoryID = Products.CategoryID)  border=0 alt="">

        INNER JOIN ((Customers 
           INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) 
              INNER JOIN [Order Details] 
ON Orders.OrderID = [Order Details].OrderID) 
   ON Products.ProductID = [Order Details].ProductID

GROUP BY Customers.CompanyName, Categories.CategoryName, 

We can run the query at this stage by selecting Query --> Run from the main menu.

13.  Save the query as ACC06-Step1.

14.  Select Query --> Run from the main menu.

The resulting dataset appears as partially shown in Illustration 8.

Illustration 8: The SELECT Query Dataset