You can use a union query to get many values at once. The query you have
could be rewritten as
SELECT "DeliveryMethod" as DataType
,tblinfantone.delivery_method
, Count(tblinfantone.delivery_method) AS
CountOfdelivery_method
FROM tblinfantone
WHERE Date_of_Birth Between DateSerial(Year(Date()),Month(Date())-1,1) and
DateSerial(Year(Date()),Month(Date())+1,0)
GROUP BY "DeliveryMethod" , tblinfantone.delivery_method
Now to get the Male and Female Count you could use
SELECT "Gender" as DataType
, tblInfantOne.Gender
, Count(Gender) as CountGender
FROM tblinfantone
WHERE Date_of_Birth Between DateSerial(Year(Date()),Month(Date())-1,1) and
DateSerial(Year(Date()),Month(Date())+1,0)
GROUP BY "Gender", tblinfantone.Gender
In a union query you would have something like the following (obviously I have
made up names for your fields):
SELECT "DeliveryMethod" as DataType
, tblinfantone.delivery_method as DataCategory
, Count(tblinfantone.delivery_method) AS theCount
FROM tblinfantone
WHERE Date_of_Birth Between DateSerial(Year(Date()),Month(Date())-1,1) and
DateSerial(Year(Date()),Month(Date())+1,0)
GROUP BY "DeliveryMethod" , tblinfantone.delivery_method
UNION ALL
SELECT "Gender" as DataType
, tblInfantOne.Gender as DataCategory
, Count(Gender) AS theCount
FROM tblinfantone
WHERE Date_of_Birth Between DateSerial(Year(Date()),Month(Date())-1,1) and
DateSerial(Year(Date()),Month(Date())+1,0)
GROUP BY "Gender", tblinfantone.Gender
UNION ALL
SELECT "BirthStatus" as DataType
, tblInfantOne.BirthStatus as DataCategory
, Count(BirthStatus) AS theCount
FROM tblinfantone
WHERE Date_of_Birth Between DateSerial(Year(Date()),Month(Date())-1,1) and
DateSerial(Year(Date()),Month(Date())+1,0)
GROUP BY "BirthStatus", tblinfantone.BirthStatus
Union queries can only be built in design view.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
reportyemi wrote:
Dirk,
Thank you. It worked. The question i have and i posted this previously is
how can i do this for all the fields and not one by one as i am doing it. In
other words can i get the total for all the fields for the preceeding month
That is
under delivereis- totla no of vaginal ,c/s and forceps for the preceding month
conditions - total number of alive babies, stillbirth babies, misccariage
babies
total number of male and female babies.
I have all of these but i have had to do querries for each field
Thanks
:
I want to find out the number of total number of all the types of
deliveries
of babies for the preceeding month. In my sql, i got the result i wanted
but
rather than getting a result like
vaginal delivery 2
c/s 5
forceps 3
i get
vag delivery 1
vag delivery 1
c/s 1
c/s 1
c/s 1
c/s 1
c/s 1
forceps 1
forceps 1
forceps 1
SELECT tblinfantone.delivery_method, Count(tblinfantone.delivery_method)
AS
CountOfdelivery_method
FROM tblinfantone
GROUP BY tblinfantone.delivery_method, tblinfantone.Date_of_Birth
HAVING
(((Year([tblinfantone]![Date_of_Birth])*12+DatePart("m",[tblinfantone]![Date_of_Birth]))=Year(Date())*12+DatePart("m",Date())-1));
You need to take the Date_of_Birth field out of the GROUP BY clause, just
group by the delivery method, and change the HAVING clause to a WHERE
clause:
SELECT
tblinfantone.delivery_method,
Count(tblinfantone.delivery_method) AS CountOfdelivery_method
FROM tblinfantone
WHERE
(((Year([tblinfantone]![Date_of_Birth])*12+DatePart("m",[tblinfantone]![Date_of_Birth]))=Year(Date())*12+DatePart("m",Date())-1))
GROUP BY tblinfantone.delivery_method
I'm not sure what your WHERE/HAVING criterion is trying to do, though. It's
possible it could be done simpler.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)