x

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, 2012 at 03:09 PM in Default

n3w2sql gravatar image

n3w2sql
850 14 22 33

(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, 2012 at 03:23 PM

Kev Riley gravatar image

Kev Riley ♦♦
52.8k 47 49 76

(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, 2012 at 03:44 PM

n3w2sql gravatar image

n3w2sql
850 14 22 33

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

x1834

asked: May 21, 2012 at 03:09 PM

Seen: 376 times

Last Updated: May 21, 2012 at 03:44 PM