Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 calculating percentages

Author  Topic 

Shelly1
Starting Member

25 Posts

Posted - 2010-02-18 : 06:02:57
Hi all,

I am trying to calculate the percentage of the following:

[ARefd] =sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end),

[TotalARefd] =sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end),

[%_Refd]

If anyone can help that would be great thanks

Mich

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-18 : 06:08:38
quote:
Originally posted by Shelly1

Hi all,

I am trying to calculate the percentage of the following:

[ARefd] =sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end)*100.0/count(1),

[TotalARefd] =sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end)*100.0/count(1),

[%_Refd]

If anyone can help that would be great thanks

Mich


modify like above and see

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Shelly1
Starting Member

25 Posts

Posted - 2010-02-18 : 06:25:18
Sorry possibly my description is misleading

I want to divide the ARefd by the TotalARefd

If i were to do a calculation on the calculator it would be ARefd/TotaARefd

Sorry if i have misleaded you.

Thanks

Mich
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-18 : 06:47:11
[code]sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end)*1.0/sum (case when Priority ='red' or Priority ='purple' and TimeArrived is null then 1 else 0 end)[/code]

use 100.0 instead of 1.0 if you need it in percentage

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Shelly1
Starting Member

25 Posts

Posted - 2010-02-18 : 07:34:28
Thanks you very much that is great.

Mich
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-18 : 07:35:20
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-18 : 07:41:07
Here is why you should use 100.0 instead of 100
http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Shelly1
Starting Member

25 Posts

Posted - 2010-02-22 : 05:14:15
Thank you very much for that,



Mich
Go to Top of Page
   

- Advertisement -