473,396 Members | 1,748 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,396 software developers and data experts.

Count Records Based on Field Value

2
Hello,

I am working with an Access 2013 database supplied by a program I use at work. No one here knows how to use Access...After hours of tutorials, I've successfully made a query to pull the needed information from the supplied table. There is just one final thing I'd like to add but can't figure out how.

There is a field in the table where the value can be -1,0,1,or 2. I would like to count the number of records where this field=2. I've tried several Count IIf and Sum IIf expressions that I've seen suggested when people have posted similar questions. The results have either been that the query will run but all the fields (including previously working ones) come out blank, or the query won't even run and I get an error message about the expression being typed incorrectly or being too complex. It seems like a pretty simple thing but I'm totally stuck and desperate.

Thanks in advance to anyone with ideas!
Jan 6 '17 #1
3 3455
PhilOfWalton
1,430 Expert 1GB
Suppose your table is called "MyTable" and your field is called "MyField"

Then this SQL should give you what you want

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(MyTable.MyField) AS CountOfMyField
  2. FROM MyTable
  3. WHERE MyTable.MyField = 2;
  4.  
Or Simpler still
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(MyField) AS CountOfMyField
  2. FROM MyTable
  3. WHERE MyField = 2;
  4.  
Phil
Jan 7 '17 #2
NeoPa
32,556 Expert Mod 16PB
If you want these aggregate values AS WELL AS individual record values then you really need to consider the sense of what you're after. It's actually quite difficult to get a count (or any other aggregation) of records or values while showing individual values too. Possible, but difficult.

What exactly is it that you're after?
Jan 7 '17 #3
mozz29
2
Thanks for the replies, both of you. Finally had time to work on this again. I've been doing everything in design view because I'm not familiar with SQL, so I wasn't sure how to incorporate this into the existing query's SQL. I made a new query with that SQL to see what it would look like in design view and then tried adding that to the existing query. While it runs successfully on its own in a separate query, when added to the existing query it will run without an error but give a blank datasheet.

To answer NeoPa's question, I'm working with a testing program that saves the participants' results to this Access database. Each question in the test corresponds with a record in the table, so for every test completed by each applicant there are roughly 20-30 records. One of the fields records the location of their response as either -1, 0, 1, or 2. I currently have a query that returns all the tests from a given participant, along with information like how many questions were completed and how many were correct. I'm trying to add information about biases towards specific locations, which is why I'm trying to figure out how to add this count of records where the field=2.
Jan 13 '17 #4

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

Similar topics

5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
10
by: jqq | last post by:
SQL2K on W2Kserver I need some help revamping a rather complicated query. I've given the table and existing query information below. (FYI, changing the database structure is right out.) The...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
3
by: brian.a.kennedy | last post by:
I am a rookie and am looking to create records based on a field value. For example - I currently have sales data for three employees: Employee 1 has sold 12 units, EE 2 has 8 and EE 3 has 10....I...
2
by: ricktech101 | last post by:
Hi, I have a table with a field that shows the number of pieces that a parcel contains. It looks like this: ParcelID, Pieces, Description Data example: 1001, 5, Jackets 1002, 10, shoes etc
2
by: Brave | last post by:
I'm hoping someone can help me with a small issue. I have an asp page that displays informaton from an Access database. I want to create a form that allows users to display only data that...
4
by: kv29 | last post by:
Hi everyone! I really hope my problem will be a piece of cake for an expert coder :) I have a table with 100 records, and I need to print them all between 10 different reports based on each...
6
by: BEETHOVEN | last post by:
I have an option group called Issue_Type on my main form F1_Member_Demographics_Main. When I select one of the 3 options on the main form from the option group Issue_Type I want to limit the sub...
5
by: Redbeard | last post by:
I am trying to change the font colour of certain records in a Multiple Item Form based on what value is in a Combo-box. The code below works for a single record view form but not the multi. It will...
12
by: shooshed | last post by:
I’m having trouble with a report field. Need it to count records in a table only where BOTH: 1. Field1 – date is less than 1/1/2013; and 2. Field2 – is null In the table, Fields 1 and 2 are...
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: 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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
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,...

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.