x
login about faq Site discussion (meta-askssc)

Percentages

Hi I am trying to do a percentage calculation and I dont know how to get it to work in sql. I am trying to get a success% ie [Total In] 91, [on time] 44, Late 47, [Success] answer would be 48%. can anyone tell me how to do this calculation?

If anyone knows how to do this I would be very grateful.

more ▼

asked May 21 '12 at 03:09 PM in Default

n3w2sql gravatar image

n3w2sql
730 5 11 18

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

2 answers: sort voted first

Try this. If the fields are integers you will need to convert [on time] to a decimal, otherwise you will be doing integer divsion

select ([on time] * 1.0) / [Total In] as Success

that will give 0.48

more ▼

answered May 21 '12 at 03:23 PM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 38 43 69

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

Thanks :), I had to convert it so it now shows as 0.48

more ▼

answered May 21 '12 at 03:44 PM

n3w2sql gravatar image

n3w2sql
730 5 11 18

(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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1601

asked: May 21 '12 at 03:09 PM

Seen: 200 times

Last Updated: May 21 '12 at 03:44 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.