SQL Calculate Percentage

Hi Experts,
I'm trying to calculate the percentage of complaint and compliment letters from the total number of letters received. The query below doesn't seem to calculate it correctly. (e.g. instead of 33.33% is shows 3.03%)
How can this query be modified so that it displays the correct percentage?
Thank you for your help
Set sqlCount = Server.CreateObject("ADODB.Command")
sqlCount.Prepared = true
sqlCount.CommandText = "SELECT cast(cast(COUNT(id) as decimal)*100 / cast((SELECT COUNT(*) FROM HR_Letters)as decimal )as decimal(5,2)) as avg FROM HR_Letters WHERE Letter='Compliment'"
set objRs = sqlCount.Execute
CountID = objRs("avg")
Set ObjRs = Nothing

Open in new window

romsomIT DeveloperAsked:
Who is Participating?
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.

Kyle AbrahamsSenior .Net DeveloperCommented:
you have the * 100 on the wrong side of the /

"SELECT cast(cast(COUNT(id) as decimal) / cast((SELECT COUNT(*) FROM HR_Letters) as decimal ) * 100  as decimal(5,2)) as avg FROM HR_Letters WHERE Letter='Compliment'"
romsomIT DeveloperAuthor Commented:
I've made the change but the result is the same. It still displays 3.03 instead of 33.33
Ess KayEntrapenuerCommented:
SELECT cast(cast(COUNT(id) as decimal) / cast((SELECT COUNT(*) FROM HR_Letters)as decimal )as decimal(5,2))*100 as avg FROM HR_Letters WHERE Letter='Compliment'"

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
romsomIT DeveloperAuthor Commented:
Thank you for your help. Both solutions are correct.
It just skipped my attention that I have to add and extra condition in my customized query.
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 SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.