473,407 Members | 2,676 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,407 software developers and data experts.

Getting total counts of types in column, for example gender

I have a table (tblMain) with field Gender. I am trying to get a count in SQL of Female and Male personnel so I can update a form containing two fields "Male = and Female = ".

The values stored in the tbl are "M and F".

Thanks!
Jul 16 '12 #1

✓ answered by twinnyfo

If you wanted ultra simple, have a tiny subform linked tothe following query:

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf([Gener]= "M",1,0)) AS Male, Sum(IIf([Gender] = "F",1,0)) AS Female
  2. FROM tblYourTable;
  3.  
Then the values would be updated every time..... I find having an unbound control that executes a DCount() often seems to really slow down the form.

13 4714
zmbd
5,501 Expert Mod 4TB
What have you tried so far?
Jul 16 '12 #2
Rabbit
12,516 Expert Mod 8TB
Use an aggregate query grouping by the gender. If you really need the results in two different columns, use a cross tab.
Jul 16 '12 #3
zmbd
5,501 Expert Mod 4TB
ahh, rabbit... I was going to suggest that... just wanted to see what they had tried so far :)

(although I have a warm fuzzy that I was on the right track)

:)

-z
Jul 16 '12 #4
I have tried the aggregate query.

This query gives me the correct counts, but not sure how to call the count number in the report field:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblMain.Gender, Count(tblMain.Gender) AS CountOfGender
  2. FROM tblMain
  3. GROUP BY tblMain.Gender;
  4.  
The report has a txtMale & txtFemale box.

Thanks!
Jul 18 '12 #5
zmbd
5,501 Expert Mod 4TB
Are you adding the counts to a new report or an exsisting one?

* We should probabily split at this point given the question in OP appears to be answered.
Jul 18 '12 #6
lyodmichael
75 64KB
hmm, do you try to seperate the 2 gender for two query? exp: select tblmain.gender count(tblmain.gender) as ... where gender = "male,m,Male" . because when you use group, i think you can show the 2 fields .

its just my advice,
Jul 18 '12 #7
zmbd
5,501 Expert Mod 4TB
lyodmichael
I wasn't very clear... if artemetis is creating a new report then simply using the query as the record source will be fairly easy to do by simply assigning the control source of the text fields to the correct query fields in the detail section of the report. The wizard actually doesn't do a bad job of creating a very simple report.

However, if artemetis is trying to add this information to an existing report then there are few hoops to jump thru to get the counts.

*This is why I have asked the thread to be re-posted as a new question as this is a seperate issue from the OP

-z
Jul 18 '12 #8
Thanks folks.

ZMBD - I'm adding this to an existin report, which contains sub-reports.

Funny thing, when creating a "New Report" when using the SQL as a datasource, I'm able to get a report showing
F - 32
M - 40

As soon as I add a subform, the subform gets displayed twice with a genderCount as a header.

(feel free to split this thread as necessary)
Jul 19 '12 #9
zmbd
5,501 Expert Mod 4TB
If you added the subform to the details section of the main form (or report) then yes, the subform will repeat for each of the grouped entries, in this case "m" and "f" so you get two... if you had "m", "f", and "h" you'd get three and so on.

If you need to get a count of the M and F to fall in the footer or header of the report there are several different ways to do that depending on how the report is bound to the record source and how it is layed out.. one way is to place a textbox in the header/footer of the form and set the control source of the text box so that you have something along the lines of
Expand|Select|Wrap|Line Numbers
  1. =Format(Count([ChangeToYourRSFieldName]),"Fixed")
and so forth.

-z
Jul 19 '12 #10
My main report is bound to tblMain.
This tbl has empFirstName, empLastName, empGender

I have two text boxes in the header:
txtMaleCount and txtFemaleCount

I've tried several ways to get the counts into each text box, with no success. Zmbd's last respone^^^, second paragraph, is what I'm trying to do.

Thanks, in advance.
Jul 23 '12 #11
Rabbit
12,516 Expert Mod 8TB
It may be simpler if you just used unbound textboxes and set the control source to a DCount().
Jul 23 '12 #12
twinnyfo
3,653 Expert Mod 2GB
If you wanted ultra simple, have a tiny subform linked tothe following query:

Expand|Select|Wrap|Line Numbers
  1. SELECT Sum(IIf([Gener]= "M",1,0)) AS Male, Sum(IIf([Gender] = "F",1,0)) AS Female
  2. FROM tblYourTable;
  3.  
Then the values would be updated every time..... I find having an unbound control that executes a DCount() often seems to really slow down the form.
Jul 24 '12 #13
Thanks, Twinnyfo!
That did it!!!
Jul 25 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

38
by: Kai Jaeger | last post by:
I am playing with setting font sizes in CSS using em as unit of measurement. All seems to be fine. Even Netscape Navigator shows the characters very similar to IE, what is not the kind if px is...
22
by: campbellbrian2001 | last post by:
Thanks in Advance! ... I have two textboxes: 1 is visible (and gets its value based on the invisible textbox and displays either "Male" or "Female", and needs to display either male of female based...
26
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns...
13
by: Missionary2008 | last post by:
I'm using Access 2007 with Vista. I'm trying to figure out how to write a query to take information in the fields GENDER, RETIREMENT DATE, and REGION to get a count of the number of missionaries that...
3
by: dixiebuyer | last post by:
I have a project I am porting to the Web from stand alone Access and Word with VB. I have been pleased with LAMP so far, but this one part of the project is killing me! Basically what I want to do...
3
by: JamesDelaney | last post by:
Hello All, I'm new to XSLT and XML, so please excuse the basic question. I'm trying to apply a number of conditional xsl:if statements to xsl:for-each-group, but it does not filter out the...
8
by: faefaeus | last post by:
Hi, I am trying to validate against gender in my code. The function below accepts student details, part of its function is to verify that the correct lettter is enterd for gender 'm' or 'f' It...
5
by: Bob Lee | last post by:
Access 2010. I have a drop down list with "Male" or "Female" as the choice. I wish to count the number of Males and the number of Females to show on a report. The Field name is which is stored in a...
2
by: Swapnil Mestry | last post by:
I want to display record in this format: PATIENT_CODE,gender,Malecount,femalecount Select PATIENT_CODE,gender,count(*) From BABY_MASTER Where Patient_Code='KBB-04-2010-96' group by...
3
by: neelsfer | last post by:
I got this from a website for South Africa about gender and identity number: there are 13 characters in total If 7th character (from left) of the string(ID) is between 0 and 4 the person is female,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.