A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Writing a query to count records with partial match



 
 
Thread Tools Display Modes
  #1  
Old February 14th, 2008, 12:56 PM posted to microsoft.public.access.queries
Pennington
external usenet poster
 
Posts: 21
Default Writing a query to count records with partial match

? have a table of names and addresses including a 7 digit postcode E.g BA16
7TY in a list of other BA* together with TA*, GL* etc. When I create a query
with Like "BA*" in the criteria it counts individual postcodes and as few
people have exactly the same postcode I get a list of "1s" and it does not
sum them for the group. How do I write a query that counts the number of
people with the same two digits of the postcode?
  #2  
Old February 14th, 2008, 01:34 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Writing a query to count records with partial match

If you want a count of the number of clients in each grouping by the first 2
characters of the postcode, something like this should do it:

SELECT Left([Postcode],2) AS PostcodePrefix,
Count(ClientID) AS NumberOfClients
FROM tblClient
GROUP BY Left([Postcode],2);

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

"Pennington" wrote in message
...
? have a table of names and addresses including a 7 digit postcode E.g
BA16
7TY in a list of other BA* together with TA*, GL* etc. When I create a
query
with Like "BA*" in the criteria it counts individual postcodes and as few
people have exactly the same postcode I get a list of "1s" and it does not
sum them for the group. How do I write a query that counts the number of
people with the same two digits of the postcode?


  #3  
Old February 14th, 2008, 03:17 PM posted to microsoft.public.access.queries
Pennington
external usenet poster
 
Posts: 21
Default Writing a query to count records with partial match

Thanks, I would try this if I knew how as I am not fluent in VB. I have the
Query open in Design View, where do I put these instructions? I have 2
columns
Column 1
Field: Postcode
Table: Clients
Total: Group By
Sort: Blank
Show: Checked
Criteria: Blank
or: Blank

Column 2
Field: Count Of Clients: Count(*)
Table: Blank
Total: Expression
Sort: Blank
Show: Checked
Criteria:Blank
or:Blank



"Allen Browne" wrote:

If you want a count of the number of clients in each grouping by the first 2
characters of the postcode, something like this should do it:

SELECT Left([Postcode],2) AS PostcodePrefix,
Count(ClientID) AS NumberOfClients
FROM tblClient
GROUP BY Left([Postcode],2);

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

"Pennington" wrote in message
...
? have a table of names and addresses including a 7 digit postcode E.g
BA16
7TY in a list of other BA* together with TA*, GL* etc. When I create a
query
with Like "BA*" in the criteria it counts individual postcodes and as few
people have exactly the same postcode I get a list of "1s" and it does not
sum them for the group. How do I write a query that counts the number of
people with the same two digits of the postcode?



  #4  
Old February 14th, 2008, 03:43 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Writing a query to count records with partial match

1. Open your query in design view.
Then switch it to SQL View (view menu.)

2. Paste in the SQL statement
Use your table name in place of tblClient
Use your Postcode field name in place of Postcode.
Use your primary key field in place of ClientID.

3. You can then switch back to design view.

Alternatively, just type:
Left([Postcode],2)
into the Field row in query design.

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

"Pennington" wrote in message
news
Thanks, I would try this if I knew how as I am not fluent in VB. I have
the
Query open in Design View, where do I put these instructions? I have 2
columns
Column 1
Field: Postcode
Table: Clients
Total: Group By
Sort: Blank
Show: Checked
Criteria: Blank
or: Blank

Column 2
Field: Count Of Clients: Count(*)
Table: Blank
Total: Expression
Sort: Blank
Show: Checked
Criteria:Blank
or:Blank



"Allen Browne" wrote:

If you want a count of the number of clients in each grouping by the
first 2
characters of the postcode, something like this should do it:

SELECT Left([Postcode],2) AS PostcodePrefix,
Count(ClientID) AS NumberOfClients
FROM tblClient
GROUP BY Left([Postcode],2);

"Pennington" wrote in message
...
? have a table of names and addresses including a 7 digit postcode E.g
BA16
7TY in a list of other BA* together with TA*, GL* etc. When I create a
query
with Like "BA*" in the criteria it counts individual postcodes and as
few
people have exactly the same postcode I get a list of "1s" and it does
not
sum them for the group. How do I write a query that counts the number
of
people with the same two digits of the postcode?


  #5  
Old February 14th, 2008, 04:09 PM posted to microsoft.public.access.queries
Pennington
external usenet poster
 
Posts: 21
Default Writing a query to count records with partial match

Thanks very much, it worked a treat and I have learned a bit more about using
Access.

"Allen Browne" wrote:

1. Open your query in design view.
Then switch it to SQL View (view menu.)

2. Paste in the SQL statement
Use your table name in place of tblClient
Use your Postcode field name in place of Postcode.
Use your primary key field in place of ClientID.

3. You can then switch back to design view.

Alternatively, just type:
Left([Postcode],2)
into the Field row in query design.

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

"Pennington" wrote in message
news
Thanks, I would try this if I knew how as I am not fluent in VB. I have
the
Query open in Design View, where do I put these instructions? I have 2
columns
Column 1
Field: Postcode
Table: Clients
Total: Group By
Sort: Blank
Show: Checked
Criteria: Blank
or: Blank

Column 2
Field: Count Of Clients: Count(*)
Table: Blank
Total: Expression
Sort: Blank
Show: Checked
Criteria:Blank
or:Blank



"Allen Browne" wrote:

If you want a count of the number of clients in each grouping by the
first 2
characters of the postcode, something like this should do it:

SELECT Left([Postcode],2) AS PostcodePrefix,
Count(ClientID) AS NumberOfClients
FROM tblClient
GROUP BY Left([Postcode],2);

"Pennington" wrote in message
...
? have a table of names and addresses including a 7 digit postcode E.g
BA16
7TY in a list of other BA* together with TA*, GL* etc. When I create a
query
with Like "BA*" in the criteria it counts individual postcodes and as
few
people have exactly the same postcode I get a list of "1s" and it does
not
sum them for the group. How do I write a query that counts the number
of
people with the same two digits of the postcode?



 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.