473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Combining totals for 2 different fields

Hi,

I really hope you can help. I have a databse which records
interventions in patients drug therapy. Each record in the main table
contains 3 fields to capture the 3 main drug names involved in the
intervention and they are called PrimDrug, SecondaryDrug1,
SecondaryDrug2. The drug names are selected from another table called
Drug. What I want to do is to have a graph illustrate the top ten
drugs involved. While it is easy to do this for each field/category, I
am not sure how I can combine the names from all three field in a query
and do a global count of all the drugs involved for all of the records
regardless of the prmary or secondary category.

I bet its really simple but I am having a block. Hope to hear from you
soon!

MacBane

Aug 3 '06 #1
1 1862
You could combine the values from the 3 fields into a single query like
this:

SELECT PrimDrug FROM Table1 WHERE PrimDrug Is Not Null
UNION ALL
SELECT SecondaryDrug1FROM Table1 WHERE SecondaryDrug1Is Not Null
UNION ALL
SELECT SecondaryDrug2FROM Table1 WHERE SecondaryDrug2Is Not Null;

Replace Tabe1 with your table name. Access cannot show that query
graphically, but it should work in SQL View.

A better solution would be to normalize the data by creating a related
table, where can have many *records* for the drugs used in each case,
instead of the 3 fields. Whenever you have repeating fields like these 3, it
always indicates that you should use a related table instead.

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

"Macbane" <jo*******@sch.nhs.ukwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
I really hope you can help. I have a databse which records
interventions in patients drug therapy. Each record in the main table
contains 3 fields to capture the 3 main drug names involved in the
intervention and they are called PrimDrug, SecondaryDrug1,
SecondaryDrug2. The drug names are selected from another table called
Drug. What I want to do is to have a graph illustrate the top ten
drugs involved. While it is easy to do this for each field/category, I
am not sure how I can combine the names from all three field in a query
and do a global count of all the drugs involved for all of the records
regardless of the prmary or secondary category.

I bet its really simple but I am having a block. Hope to hear from you
soon!

MacBane

Aug 3 '06 #2

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
5
by: M.Stanley | last post by:
Hi, I'm attempting to create a query that will combine 2 columns of numbers into one. The followng comes from 1 table with 4 fields (A,B,C,D) A B RESULT 700 000 700000 700 001 ...
0
by: Julio Sarmiento | last post by:
I have a table containing the following fields: rep numbers, year, month, qty, revenue, credit apps, new accounts. The data in this table reflects the rep's daily numbers. What I need to do is...
0
by: Sam.Moretta | last post by:
Hey all. Ive got a big problem with an sql statement Im working on. There are 2 tables with a master/detail relationship. The Header Table is the master, the Line Table is the detail. So for each...
3
by: brm6546545 | last post by:
I have a tblTax. It has fields InvoiceNum, TaxAuthority, TaxableTotal, NonTaxableTotal, TaxCollected. Sample data 1,county,10.00,0.00,0.40 1,city,10.00,0.00,0.10 2,state,0.00,15.00,0.15 ...
10
by: rdemyan via AccessMonster.com | last post by:
I have a subform that displays around 10 fields. Most of the values shown result from some complex calculations. To make it easy, I have stored the results in a temporary table and then all I...
7
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !!...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
2
by: billelev | last post by:
Does anyone know if it is possible to combine two queries that have the same fields? I basically want to combine a number of fields with the totals for those fields into one query (see example...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.