Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Percent of Total results from a query

Posted on 2003-11-19
15
Medium Priority
?
838 Views
Last Modified: 2012-06-21
Hello!

Here is my SQL satement thus far for ReasonsQuery:

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));

This returns a REASON and the total count of that reason within the SQqryGetOrgWorkedData query.

I would like another field, perhaps in this query, but it can be in another query that uses the ReasonsQuery if needed. This field would show the PERCENT for each REASON. So... if the total of all CountOfReasons = 100 and Reason1 = 10, I would like to know that Reason1 is %10 of the total. The "%" sign is not necessary but it would be nice.

Thanks in advance for all your help!
0
Comment
Question by:sph3rion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
15 Comments
 
LVL 5

Expert Comment

by:morpheus30
ID: 9780698
SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 * (SQqryGetOrgWorkedData.Reasons / Count(SQqryGetOrgWorkedData.Reasons)) AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780854
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780855
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Author Comment

by:sph3rion
ID: 9780859
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780864
'The expression is typed incorrectly, or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.'

Is the error I get using that morpheus30.

It went to design view alright though...
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9780872
Sigh... sorry about that, work network said page cannot be displayed
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9780949
My bad, dude...

I did that carelessly.  Try this...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 *(Count(SQqryGetOrgWorkedData.Reasons) / SELECT Count(*) FROM SQqryGetOrgWorkedData)  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781070
Syntax error on: 100 *(Count(SQqryGetOrgWorkedData.Reasons) / SELECT Count(*) FROM SQqryGetOrgWorkedData)

Highlights SELECT

Just as a note, the total count of reasons is not necessarily 100... it's different each time and is probably going to be some odd number like 2567. If that has anything to do with anything, I'm stumped right now.
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781116
Hey sph3rion,

What version of Access are you using?
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781134
Access 2000 sir
0
 
LVL 5

Accepted Solution

by:
morpheus30 earned 2000 total points
ID: 9781198
Ooops....

I forgot the Parentheses...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, 100 *(Count(SQqryGetOrgWorkedData.Reasons) / (SELECT Count(*) FROM SQqryGetOrgWorkedData))  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781262
Better yet...

SELECT DISTINCT SQqryGetOrgWorkedData.Reasons, Count(SQqryGetOrgWorkedData.Reasons) AS CountOfReasons, FormatPercent(Count(SQqryGetOrgWorkedData.Reasons) / (SELECT Count(*) FROM SQqryGetOrgWorkedData), 2)  AS PctOfReasons
FROM SQqryGetOrgWorkedData
GROUP BY SQqryGetOrgWorkedData.Reasons
HAVING (((SQqryGetOrgWorkedData.Reasons) Not In ("Closed Correctly")));
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781353
BINGO

I don't have FormatPercent though... is that Access XP?
0
 
LVL 1

Author Comment

by:sph3rion
ID: 9781361
Thank you so very much by the way :)
0
 
LVL 5

Expert Comment

by:morpheus30
ID: 9781381
hmmm...

The FormatPercent is supposed to be a standard VBScript function.  As a matter of fact, I am using Access XP, but in Access 2000 format.  It is quite possible that they made a change to support this function in XP and not in 2000.  

Anyway, glad things worked out for you!

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question