Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / November 2006

Tip: Looking for answers? Try searching our database.

Simple query help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tom.youdan@googlemail.com - 30 Nov 2006 05:45 GMT
Hi,

I have an access dbs with 2 key tables. One is a State table that has
State id and State name fields. This feeds a combo box in a form to
provide a reference point for the State Id field in the Main table.
This allows multiple State instances, as I am mapping a number of
organizations in each state.

The main table has one entry per organization and one state reference
per line. It also has 7 Yes/No fields to identify what technology each
org has.

What I want is a query that gives me a full list if states and a count
of how many of each tech they have.

I have made queries that show a count of each technology per state, but
not one that gives all. The closest I have come is to have a report
that gives all, but only if there is at least one instance of each
technology per state. As I said, I want to know when there are no
instances of a tech in a state.

Sorry for the long winded question..not very good at explaining...

Any help would be great.

Thanks,

Tom
Allen Browne - 30 Nov 2006 06:58 GMT
This is not the best way to design these tables, but here's a trick to get
you out of trouble.

Internally Access uses -1 for True, and 0 for False. Therefore if you sum
the yes/no field, you get the negative of the number of Yes answers.

Steps:

1. Create a query using this table.

2. Depress the Total button on the toolbar.
Access adds a Total row to the grid.

3. Drag the State identifier into the grid.
In the Total row under this field, accept Group By.

4. Drag each of the Technology fields into the grid.
In the Total row, choose Sum.

Once you have that working, if you want to change the negatives to
positives, switch the query to SQL View (View menu), and add a minus before
the calcuations. For example, change:
   Sum(Table1.Astronomy) AS SumOfAstronomy
to:
   -Sum(Table1.Astronomy) AS SumOfAstronomy

To explain the comment in the first paragraph, it would be a much better
design to create a Technology table where you have 7 records for the 7 types
of technology, and then an OrganizationTechnology table with fields:
   TechnologyID    relates to Technology.TechnologyID
   OrganizationID  relates to Organization.OrganizationID
   StateID             relates to State.StateID
If an organization handles 5 technologies in Iowa, they have 5 rows. If they
handle 2 in Kansas, that's another 2 records. Now there's only one field to
search, count, whatever, for all the technologies.

Technically, this is called a "junction" table, and it is the standard way
of resolving the many-to-many relation that exists between technologies and
organizations into a pair of one-to-many relations. If that's a new concept,
there's another example here:
   http://allenbrowne.com/casu-06.html

Signature

Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> I have an access dbs with 2 key tables. One is a State table that has
> State id and State name fields. This feeds a combo box in a form to
[quoted text clipped - 14 lines]
> technology per state. As I said, I want to know when there are no
> instances of a tech in a state.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.