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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 subquey help

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2011-11-29 : 13:42:32
Hi

I have many bit fields in my table and want to present the information in this format:


Category Calls Passed Calls Reviewed Percent Passed
Identified Self 252 254 99%
Spoke Clearly 251 254 98%
Promptness 253 254 99%


The bit field names are:
G_Name
G_Clear
G_Prompt

I've done this but it's not what I need.

SELECT
count(g_name) as GNamePassed, --This needs to count only values where G_name = 1
count(reviewid) as CallsReviewed,
count(g_name) / count(reviewid) * 100 As PctngPassed
FROM
Calls

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-11-29 : 13:50:32
You can use a case expression within the count function to count only those for whichg G_name=1, like this:
SELECT
COUNT(case when G_name = 1 then g_name END ) AS GNamePassed, --This needs to count only values where G_name = 1
COUNT(reviewid) AS CallsReviewed,
(1.0*COUNT(g_name)) / COUNT(reviewid) * 100 AS PctngPassed
FROM
Calls
Go to Top of Page

evanburen
Posting Yak Master

167 Posts

Posted - 2011-11-29 : 13:58:44
That's very helpful.

Is there anyway to loop through all of these bit values and have them all in one set of results like my example?

Thanks
Go to Top of Page
   

- Advertisement -