Query Help - How to total checked boxes?

M

Mel

Can anyone PLEASE assist me with my SQL Select query? I have a table
that keeps track of user login information so there will be many
records for a given user. I have 5 boolean fields which are displayed
as check boxes (reference library, quotes, tracking, training,
calculators). How do I display the total of these boolean fields for
a given user (I only want the boxes that are checked)? When I run the
query I don't want to show each of the user's logins, I want it to
group the particular user's login data and just show one record which
contains the totals for the boolean fields. Any help would be greatly
appreciated.

Here is the query I have now:
SELECT Company, User, [Reference Library], Quotes, Tracking, Training,
[Calculators
FROM [Web User Log]
WHERE (((Company)="ABC, LLC") AND ((User)="jdoe"))
ORDER BY Company, User;

Here is the results of my query now:
Company User Reference Library Quotes Tracking Training Calculators
ABC, LLC jdoe No No No No No
ABC, LLC jdoe No No No No Yes
ABC, LLC jdoe No No Yes No No
ABC, LLC jdoe Yes Yes No Yes Yes

What I really want is this (just count the "Yes" records for that
user). How do I do it?:
Company User Reference Library Quotes Tracking Training Calculators
ABC, LLC jdoe 1 1 1 1 2
 
M

Mel

Can anyone PLEASE assist me with my SQL Select query? I have a table
that keeps track of user login information so there will be many
records for a given user. I have 5 boolean fields which are displayed
as check boxes (reference library, quotes, tracking, training,
calculators). How do I display the total of these boolean fields for
a given user (I only want the boxes that are checked)? When I run the
query I don't want to show each of the user's logins, I want it to
group the particular user's login data and just show one record which
contains the totals for the boolean fields. Any help would be greatly
appreciated.

Here is the query I have now:
SELECT Company, User, [Reference Library], Quotes, Tracking, Training,
[Calculators
FROM [Web User Log]
WHERE (((Company)="ABC, LLC") AND ((User)="jdoe"))
ORDER BY Company, User;

Here is the results of my query now:
Company User Reference Library Quotes Tracking Training Calculators
ABC, LLC jdoe No No No No No
ABC, LLC jdoe No No No No Yes
ABC, LLC jdoe No No Yes No No
ABC, LLC jdoe Yes Yes No Yes Yes

What I really want is this (just count the "Yes" records for that
user). How do I do it?:
Company User Reference Library Quotes Tracking Training Calculators
ABC, LLC jdoe 1 1 1 1 2

That figures, right after I post my question I figure it out! Here is
my new SQL statement if anyone is interested:

SELECT Company, User, Count(IIf([Reference Library]=True,[Reference
Library],Null)) AS [Ref Library Page], Count(IIf([Quotes]=True,
[Quotes],Null)) AS [Quote Page], Count(IIf([Tracking]=True,
[Tracking],Null)) AS [Tracking Page], Count(IIf([Training]=True,
[Training],Null)) AS [Training Page], Count(IIf([Calculators]=True,
[Calculators],Null)) AS [Calculator Page]
FROM [Web User Log]
GROUP BY Company, User
ORDER BYCompany, User;
 
J

Jerry Whittle

SELECT Company,
User,
Sum(Abs([Reference Library])) AS SumRefLibrary,
Sum(Abs(Quotes)) AS SumQoutes,
Sum(Abs(Tracking)) AS SumTracking,
Sum(Abs(Training)) AS SumTraining,
Sum(Abs(Calculators)) AS Sum Calculators
FROM [Web User Log]
WHERE Company ="ABC, LLC"
AND User ="jdoe"
GROUP BY Company, User
ORDER BY Company, User ;

One other problem is that you have Yes/No boolean fields going across. What
happens if you have to add another like, say, Efficiency? You'll have to
modify the table, queries based on the table, and any forms and reports. You
should really look into normalizing the data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top