473,765 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count records Contian specific string values

I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values

If the field contains "AAA" the count is X.
if the field contains "CCC" the count is Y.
if the field contains "Stop" then count is Z.

I have tried several ways and can not seem to get any where. I get
the same count for all string values. Can some one please send me a
sample query that I could look at and study.

Apr 11 '07 #1
2 12079
The field could contain more than one thing, e.g. it might be:
AAA is CCC, so please Stop.

So, you cannot get this kind of answer from any grouping. You will need to
use a subquery to return the count.

1. Create a query without any table in the upper pane of query design.

2. Type this into the Field row:
CountAAA: (SELECT Count(ID) FROM Table1 WHERE Field1 LIKE "*AAA*")

3. Replace Table1 with your table, name, ID with the name of your primary
key field, and Field1 with the name of the field that might contain the AAA.

4. Test.

5. Once you have it working, type a similar expression into the next column
in the Field row, to match the CCC text.

6. Repeat in the next column for the "Stop" text.

If subqueries are new, see:
http://allenbrowne.com/subquery-01.html

If this is an important query, there may be a better way to design this
table.
The query will be *very* slow to run.
It is error prone (e.g. where someone typed Drop instead of Stop.)
And results are poor (e.g. if you search for Top, you find it in Stop,
Topic, etc.)

So perhaps something like a related table of keywords would give more
accurate results, lightening fast, and make the querying much easier.

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

"Pete" <pe********@com cast.netwrote in message
news:11******** *************@e 65g2000hsc.goog legroups.com...
>I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values

If the field contains "AAA" the count is X.
if the field contains "CCC" the count is Y.
if the field contains "Stop" then count is Z.

I have tried several ways and can not seem to get any where. I get
the same count for all string values. Can some one please send me a
sample query that I could look at and study.
Apr 12 '07 #2
On Apr 11, 9:26 pm, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
The field could contain more than one thing, e.g. it might be:
AAA is CCC, so please Stop.

So, you cannot get this kind of answer from any grouping. You will need to
use a subquery to return the count.

1. Create a query without any table in the upper pane of query design.

2. Type this into the Field row:
CountAAA: (SELECT Count(ID) FROM Table1 WHERE Field1 LIKE "*AAA*")

3. Replace Table1 with your table, name, ID with the name of your primary
key field, and Field1 with the name of the field that might contain the AAA.

4. Test.

5. Once you have it working, type a similar expression into the next column
in the Field row, to match the CCC text.

6. Repeat in the next column for the "Stop" text.

If subqueries are new, see:
http://allenbrowne.com/subquery-01.html

If this is an important query, there may be a better way to design this
table.
The query will be *very* slow to run.
It is error prone (e.g. where someone typed Drop instead of Stop.)
And results are poor (e.g. if you search for Top, you find it in Stop,
Topic, etc.)

So perhaps something like a related table of keywords would give more
accurate results, lightening fast, and make the querying much easier.

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

"Pete" <petebea...@com cast.netwrote in message

news:11******** *************@e 65g2000hsc.goog legroups.com...
I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values
If the field contains "AAA" the count is X.
if the field contains "CCC" the count is Y.
if the field contains "Stop" then count is Z.
I have tried several ways and can not seem to get any where. I get
the same count for all string values. Can some one please send me a
sample query that I could look at and study.- Hide quoted text -

- Show quoted text -
Thanks,
I think I will create a report and use the dcount function. The data
is used very infrequently and comes from a survey. It looks like the
dcount is probably a better way to go.

Apr 12 '07 #3

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

Similar topics

0
2179
by: kovac | last post by:
The System.directoryservices.dll has an error, and this error was described in http://support.microsoft.com/default.aspx?scid=kb;en-us;839424 At the moment we have Framework version v1.0.3705 and I have remove System.directoryservices.dll from current Framework version v1.0.3705. In state of old version I load die new System.directoryservices.dll from the Framework version v1.1.4322. I work with the following function of Joe Kaplan...
2
7826
by: SJM | last post by:
I have a report that displays records of real estate properties. It is possible for each property to appear a number of times for various reasons. Each record however is unique. What I would like to do is display the total of the number of unique properties in the report footer, not just a count of the number of records. I have experimented with grouping on the property field and using running sums but to no avail. I have also tried to...
1
2412
by: JMCN | last post by:
hello- i have created a tabular form using records from a specific query. then users will filter out the specific data. the next step is to take the count of the current records (daily open items), then use the total number of daily open items to calculate the percentage to all open items for the month. my first question is how would i be able to capture the current filtered openrecordset and count the records? would i use the
4
2024
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a datagrid isn't going to work). On this page, people can update a variet of records. On submit, I want to then go in and update all of the records. Normally, I'd make each form element include a runat: server and then declare it in my codebhind so I...
7
26823
by: Mike | last post by:
I have a form where I have turned off the default navigation buttons. I then created my own. This works fine. The only questions that I have is on the default navigation buttons it shows total records. How can I show this? I have a text box that shows the current record using: Text1 = Me.Current I want to show the total number of records. How do I do this?
22
12491
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
1
3735
by: danibecr | last post by:
I'm trying to make a table that will daily count the records imported and save them to a seperate table along with the date imported. But as of now after all the processing is complete I delete everything off of the original import tables. I have tried using a form to get the correct counts and dates which work but in order for it to run somewhat smooth the form HAS to be open otherwise it asks for paramater values. Is there an easy way to do...
1
1896
by: N06149 | last post by:
I have a report based on a query. I list an Org_Type then Org_Name then the Projects associated with it. Sample of report below: Community Type ---------------------------------------------------------Org_Type Header Org_Name bla bla bla project a project b project c -----------------------------------------------------------Org_Type Footer (=Count(*) & "...
1
3223
bilibytes
by: bilibytes | last post by:
Hi everyone, Ok I want here to make a query which will reuse the result of a count(*) function. lets say my website does events at different places for the same date, and also at different dates: this makes a structure like this: event_id | attending_id | date there may be for the SAME date: -multiple records with the same event_id and different attending_id
0
9568
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
9404
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
10164
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...
1
9959
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
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.