Simple clear advice in plain English

Hands on: Trawling engines

Just how does a database engine work? Plus a query about organising fishing data

Indeed, if we try to solve this problem with SQL then we are using the wrong tool. The database engine is not designed to present data other than in the most basic form (as tables with rows and columns) and SQL doesn’t have any constructions for presentation.

This is the kind of task a reporting tool should undertake (and the one in Access might require you to delve down into Visual Basic to produce the desired result).

If your reporting tool won’t do it, change your reporting tool. Don’t change the database engine because doing so won’t help.

Incidentally, I’m not saying that it is impossible to solve Rodney’s problem using SQL - all manner of Byzantine constructions can be dreamed up to force it to do things for which it wasn’t designed; Cartesian joins and make-table queries usually feature in them. But you’d still be using the wrong tool.

A question of fish
Fran Cobden has an Access 2000 database for storing fishing activity on sea trips and has normalised the data structure but has met a stumbling block when designing new forms. Fran wants to duplicate the look of the form from the old non-normalised regime, which used a form with an embedded sub-form.

The form shows all the details about a single trip; the sub-form had one row for each day of fishing activity on the trip, which showed the number of each species of fish caught. This was fine except that there are 45 species of fish, identified by three-letter codes, of which on average 10 are caught per trip, so the sub-form was always jam-packed full of nulls. In the new, normalised database Fran hoped to lose all of the nulls.

The normalised database has two tables - one stores details about each trip (Trip) and one records the catch made on each day of fishing (Catch). This sample database has a much simplified version of the data.

Basing a form on the Trip table is so simple that we can use the wizard. The data for the sub-form is also easy: we can use this crosstab query called CrosstabCatch:

TRANSFORM Sum(Catch.Weight)AS SumOfWeight
SELECT Catch.TripID, Catch.4DayID, Sum(Catch.Weight) ASTotalWeight
FROM Catch
GROUP BY Catch.TripID, Catch.DayID
ORDER BY Catch.DayID
PIVOT Catch.Species;

So, we’ve got the data. This is the point for Access users where the limitations of the user interface begin to bite.

The obvious approach is to embed the crosstab query as a sub-form on to a form, but Access won’t allow that. It’s possible to proceed by making the crosstab query a parameter query (remembering to specify the data type by going to Query on the main menu, Parameters). A button can then be placed on the form which runs the parameter/crosstab query. Click the button and you’ll be prompted for the ID of the trip for which you want to see the records.

Type it in and the data is displayed. It’s a kludgy solution and a work-around typical of the type constructed when the UI runs out of gas. You can also attack the problem with VB code.

The workaround solution is in the database on this month’s cover disc, using a query called Par and the form, Trip. You’ll also find the database here. You can move through the records in the main form, click the Run Query button and enter the trip ID. The crosstab displays the results.

Article tags

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

penguinbooks

Apple under scrutiny as EU begins ebook price probe

Commission looking for evidence of uncompetitive behaviour

Hands on: Connect Access and SQL Server

Just how exactly do you start using a database server?

Hands On: Different types of nothing

A debate about tables and multiple flavours of null

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Restore point

A Windows backup of system files and settings.

Great shopping deals from Computeractive