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
 Quotient

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-03-29 : 08:29:07
Table Name
ID Data1
1 Yes
2 No
3 NA

Here's my formula

SELECT SUM(CASE Data1 WHEN 'yes' THEN 1 ELSE 0 END) / (SUM(CASE Data1 WHEN 'yes' THEN 1 ELSE 0 END)
+ (SUM(CASE Data1 WHEN 'no' THEN 1 ELSE 0 END) + (SUM(CASE Data1 WHEN 'na' THEN 1 ELSE 0 END))))
FROM Test3

I can't seem to have a quotion of .33333. Can any one help me?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-03-29 : 08:35:12
similar problem as this:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99906

your "1"s and "0"s are INTs so your resulting precision can't show .3333

Be One with the Optimizer
TG
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-03-29 : 08:51:38
I'm getting 2 as the result. I think it's the position of the parenthesis "()'
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-29 : 09:43:38
SELECT SUM(CASE Data1 WHEN 'yes' THEN 1.0 ELSE 0.0 END) / (SUM(CASE Data1 WHEN 'yes' THEN 1.0 ELSE 0.0 END) + SUM(CASE Data1 WHEN 'no' THEN 1.0 ELSE 0.0 END) + SUM(CASE Data1 WHEN 'na' THEN 1.0 ELSE 0.0 END))
FROM Test3



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-03-29 : 10:06:55
i think it works. thanks
Go to Top of Page
   

- Advertisement -