473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple query help

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

Nov 30 '06 #1
1 1401
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

--
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.

<to********@googlemail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>
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.

Nov 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4734
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
3
3659
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
0
1989
by: unixman | last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to posting in the newsgroups for help. :) Simple problem, in theory. Given table "map": CREATE TABLE map ( entry_id...
1
3632
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
4
2053
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
2
8465
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so...
3
1746
by: John Baker | last post by:
Hi:7 Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have named HireInput,...
2
2378
by: Fendi Baba | last post by:
I created a person table with various fields such as Suffix, Salutation, etc, Some of these fields may not be mandatory for example suffix. In the actual table itself, I only have a field for...
9
19117
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
3
3248
by: rogynskyy | last post by:
Hi guys, I'm running MSDE 2000 A on Win XP I've got a database with several tables, all of the tables display data in query manager. I wrote this simple query: Select
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.