COUNT NUMBERS IN ROW

HAVE  TABLE_A
Fields_A, Fields_B, Fields_C, Fied_D
        3           4               6            6

need to count each number
how can i do that ??
MIKE NIKEAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
what result do expect to see?
Rey Obrero (Capricorn1)Commented:
what result do you expect to see?
Dale FyeOwner, Developing Solutions LLCCommented:
What happens when one of the fields is NULL?
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Dale FyeOwner, Developing Solutions LLCCommented:
I would create a function which accepts a parameter array, pass the field values to the function and let the function loop through the elements of the parameter array.  If the value is numeric, increment a counter, if not, skip to the next element of the array.

You would call this something like:

NumCount: fnCountNumbers([Field_A], [Field_B], [Field_C], [Field_D])

Because this function would use a parameter array, you could pass as many columns worth of data as you want.
PortletPaulEE Topic AdvisorCommented:
is this what you are after?

Fields_A, Fields_B, Fields_C, Field_D, Result?
        3           4               6            6          4
        3           4               6         NULL      3
        3           4             NULL    NULL     2

if not please supply the "expected result" from a larger sample of data
MIKE NIKEAuthor Commented:
thnks all !

my data fiels is shorttxt format

i need count numbers in this way

Fields_A, Fields_B, Fields_C, Fied_D         1    2    3   4   5   6  7   8   9   0
        3           4               6            6                            1   1        2
        2          4                0           0                        1          1                          2
       1          2                 6           1                 2     1                  1


need  it to be   count how many times the number repeat
for each number
Rey Obrero (Capricorn1)Commented:
see this sample db.
open query Q_countnumbers
db-28709626-CountNumbers.accdb

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MIKE NIKEAuthor Commented:
WOW !! YOU GREAT ! REY OBRERO!!

but i will need help please to put to work in
the database

how i do that ?
Rey Obrero (Capricorn1)Commented:
- from your database, import the module modCountNumbers from the sample db
- create a query similar to the query Q_count using your table.
aikimarkCommented:
Here's a version that uses the Regexp object to count the instances:
Function MatchCount(ByVal parmConcatFields As String, parmMatch, Optional parmDelim As String = ",") As Long
    Static oRE As Object
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
    End If
    oRE.pattern = "\b" & parmMatch & "(?:" & parmDelim & "|$)"
    If oRE.test(parmConcatFields) Then
        MatchCount = oRE.Execute(parmConcatFields).Count
    Else
        MatchCount = 0
    End If
End Function

Open in new window

You can simplify your SQL by concatenating the fields into a new field (named ConcatFields in the following example:
SELECT tableN.A, tableN.B, tableN.C, tableN.D, 
tableN.A & "," &  tableN.B & "," &  tableN.C & "," & tableN.D As ConcatFields,
CountOf(ConcatFields,1) AS 1, CountOf(ConcatFields,2) AS 2, CountOf(ConcatFields,3) AS 3, CountOf(ConcatFields,4) AS 4, CountOf(ConcatFields,5) AS 5, CountOf(ConcatFields,6) AS 6, CountOf(ConcatFields,7) AS 7, CountOf(ConcatFields,8) AS 8, CountOf(ConcatFields,9) AS 9, CountOf(ConcatFields,0) AS 0
FROM tableN;

Open in new window

When using the Regexp function, the query would look like this:
SELECT tableN.A, tableN.B, tableN.C, tableN.D, 
tableN.A & "," &  tableN.B & "," &  tableN.C & "," & tableN.D As ConcatFields,
MatchCount(ConcatFields,1) AS 1, MatchCount(ConcatFields,2) AS 2, MatchCount(ConcatFields,3) AS 3, MatchCount(ConcatFields,4) AS 4, MatchCount(ConcatFields,5) AS 5, MatchCount(ConcatFields,6) AS 6, MatchCount(ConcatFields,"7") AS 7, MatchCount(ConcatFields,"8") AS 8, MatchCount(ConcatFields,"9") AS 9, MatchCount(ConcatFields,"0") AS 0
FROM tableN;

Open in new window

Note: The MatchCount function can accept either numeric or string literals to match and can accept a different field delimiter character, as I illustrated with values 7-9,0 in the above example.
MIKE NIKEAuthor Commented:
thanks you lead the way !
MIKE NIKEAuthor Commented:
all of you thanks !!
Rey  Obrero keep the good job !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.