# 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?
``````<%
sqlCount.ActiveConnection=Conn
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")
%>
<%=CountID%>
<%
ObjRs.Close
Set ObjRs = Nothing
%>
``````
###### 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.

Senior .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'"
IT DeveloperAuthor Commented:
I've made the change but the result is the same. It still displays 3.03 instead of 33.33
EntrapenuerCommented:
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