Percentage calculation

 0 I am trying to get sql to read my percentage calculation but I cant figure it out.The calcuation is(A.[POLICY TOTAL] - [A.LATE])/A.[POLICY TOTAL] * 100 This will give me the percentage I need butat the moment I am calculating the below which gives me the opposite percentage. so I have one that gives me 20% but I need the other to show me the 80% Can anyone advise if there is such a calculation? Many thanks in advance if so. ``````CONVERT(VARCHAR,CONVERT(DECIMAL(5,1),100.0 * `````` a.[Late] / a.[POLICY TOTAL])) + '%' [Failedd] more ▼ asked Apr 27, 2012 at 10:29 AM in Default n3w2sql 850 ● 14 ● 25 ● 33 add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users

 0 You already have shown it how to do it. All you have to do is put the parentheses correctly ``````SELECT CONVERT(VARCHAR,CONVERT(DECIMAL(5,1), ((A.[POLICY TOTAL] - [A.LATE])* 100.0)/A.[POLICY TOTAL] )) + '%' [Failedd] `````` more ▼ answered Apr 27, 2012 at 10:36 AM robbin 1.6k ● 1 ● 3 ● 5 add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users
 0 Thank you for the help Robbin but its not bringing back the percentages I need ie policysin has 12 and Failed has 4 so it would give 33.3% with my calculation where as I am trying to bring back the percentage of 66.66 and so on. Sorry for not being clear. more ▼ answered Apr 27, 2012 at 10:49 AM n3w2sql 850 ● 14 ● 25 ● 33 My solution seems to be doing exactly that ``````DECLARE @policy INT, @fail INT SELECT @fail = 4, @policy = 12 SELECT CONVERT(VARCHAR,CONVERT(DECIMAL(5,1), ((@policy - @fail)* 100.0)/@policy )) + '%' [Failedd] `````` Apr 27, 2012 at 10:57 AM robbin add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

By Email:

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1847

asked: Apr 27, 2012 at 10:29 AM

Seen: 840 times

Last Updated: Apr 27, 2012 at 10:57 AM