Query to count

ukmdg

New member
Local time
Today, 20:15
Joined
Oct 6, 2007
Messages
1
I have a table with records with one field containing a comma separated string.

for example within each field this may have something like

Orange,Apple,Pear,Clementine,Melon

I need a query to count the total orange or apple etc within the table.

Is there an easy way of doing this?

Thanks in advance

UKMDG
 
Since the table is not normalized, you can use -Sum() on an InStr() expression for each of the orange, apple etc in a query like the following. And as a table has a maximum of 255 fields, you can type no more than 255 such expressions in the query.

SELECT -Sum(InStr([FieldName],"Orange")>0) AS Orange,
-Sum(InStr([FieldName],"Apple")>0) AS Apple,
-Sum(InStr([FieldName],"Pear")>0) AS Pear,
..............................
FROM [TableName];
.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom