Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 11th, 2007, 11:35 PM
Pete
Guest
 
Posts: n/a
Default 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.

  #2  
Old April 12th, 2007, 02:35 AM
Allen Browne
Guest
 
Posts: n/a
Default Re: Count records Contian specific string values

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" <petebeatty@comcast.netwrote in message
news:1176330558.401287.77350@e65g2000hsc.googlegro ups.com...
Quote:
>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.
  #3  
Old April 12th, 2007, 03:15 AM
Pete
Guest
 
Posts: n/a
Default Re: Count records Contian specific string values

On Apr 11, 9:26 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Quote:
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...@comcast.netwrote in message
>
news:1176330558.401287.77350@e65g2000hsc.googlegro ups.com...
>
>
>
Quote:
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
>
Quote:
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.
>
Quote:
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.

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles