473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count total occurrences in different fields

3 New Member
Fairly new to Access and really doesn't know much about SQL except some basic commands. Currently I'm working with a database that I've already sorted by some queries, and here's a simplified result.

Query1:
Name A B
Smith_A Ya [null]
Smith_R Yb Ya
Smith_C [null] E
Smith_B E Y

So far I can count occurrences of "Y" in single fields by using

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(*) AS NumA
  2. FROM [Query1]
  3. WHERE [Query1].A like 'Y*';
  4.  
And get result:
NumA
2

What I want as final result is to tally up total number of names and total occurences of "Y" in the 2 fields, so the final query (or report) will show:

NumPersons NumA NumB
4 2 2

Writing single query for each field then report them together is really dirty since the original database has about 70 fields and 65 records. I just wonder if there's a more elegant way of doing it.

I suppose I can always export the query to Excel and use COUNTIF to do this, but I would like to know if there's a way to write the query so I can keep it all in Access without having to write formulas in reports.

Sorry for the newbie question and thanks in advance for the help.
Nov 29 '06 #1
1 5304
NeoPa
32,579 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT Count([Name]) AS NumName,
  2.    Sum(IIf([A] Like 'Y*',1,0)) AS NumA,
  3.    Sum(IIf([b] Like 'Y*',1,0)) AS NumB
  4. FROM [Query1];
PS. Someone that cares about the elegance of code doesn't ask newbie questions!
Nov 29 '06 #2

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

Similar topics

6
44119
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr scott/tiger@common control=/full_path/test.ctl log=/full_path/adhoc/test.log SQL*Loader: Release 9.2.0.1.0 - Production on Tue Sep 2 10:49:27 2003 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
7
2574
by: Shannan Casteel via AccessMonster.com | last post by:
I have a form for entering part numbers along with the associated quantity for each part. There are 25 Part fields and 25 associated Quantity fields. If I go to record 1 and enter part number 1234 for part1, 3 for quantity1, and 1235 for part2, 8 for quantity2, and on record 2 I enter 1236 for part1, 2 for quantity1, and 1234 for part2, 2 for quantity2, how would I get Access to spit out a report that says something like this: Part...
4
55416
by: thomaz | last post by:
Hi.... There is a string method to count the total number of a specified character in a string. EX: count the total of (*) in a string *** Test *** Thanks....
14
23278
by: mesterak | last post by:
I want to very quickly count the number of lines in text files without having to read each line and increment a counter. I am working in VB.NET and C#. Does anyone have a very fast example on how to do this? Thanks, Matt
2
7279
by: KayC | last post by:
Hi I use Access2000 and am trying to count the number of columns in a table in VBA Does anyone know if this possible? thanks KC
22
12498
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
9
2039
by: nick048 | last post by:
Hi to All, I need to search the string occurencies in a structure like this: struct node { char info; struct node *next; };
1
4208
by: carolyns | last post by:
I am working with Access 2000, on Windows XP (all updates). I designed a survey in Word with 150+ questions. Roughly 60 questions use a lookup list of 7 different responses. I have the survey broken up into sections with each question numbered. As a test, I created a Survey database and chose one section of 10 questions and created a table that looks like this: ID Q1 Q2 Q3...Q10 1 3 4 7... 2 ID will link to personal...
2
3418
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The results of the analysis are to be stored in a suitable data structure. The main task in this project is to design a suitable ADT (call it WAnalysis) to store the results and enable the following operations to be performed as fast as possible:...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
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 we have to send another system

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.