x

Percentage calculation

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 '12 at 10:29 AM in Default

n3w2sql gravatar image

n3w2sql
840 12 20 26

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

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 '12 at 10:36 AM

robbin gravatar image

robbin
1.6k 1 3 5

(comments are locked)
10|1200 characters needed characters left
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 '12 at 10:49 AM

n3w2sql gravatar image

n3w2sql
840 12 20 26

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 '12 at 10:57 AM robbin
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

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

Topics:

x1816

asked: Apr 27 '12 at 10:29 AM

Seen: 716 times

Last Updated: Apr 27 '12 at 10:57 AM