| Author |
Topic |
|
sqlslick
Yak Posting Veteran
83 Posts |
Posted - 2011-11-22 : 10:03:37
|
| Hey team,I have a table in the following format:STAFF, DATE, PATIENT, COL4, COL5, COL6, COL7JOHN, 2011/11/01, BOB, TRUE, FALSE, FALSE, TRUEMIKE, 2011/11/17, MARY, FALSE, TRUE, TRUE, TRUEI want to extract all the columns above but have 2 extra columns at the end that display the total number of "TRUE" values and a percentage out of 3. Please see below:STAFF, DATE, PATIENT, COL4, COL5, COL6, COL7, SCORE, PERCENTAGEJOHN, 2011/11/01, BOB, TRUE, FALSE, FALSE, TRUE, 2, 50%MIKE, 2011/11/17, MARY, FALSE, TRUE, TRUE, TRUE, 3, 75%Thanks in advanced for your help!J |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-22 : 10:07:44
|
| [code]SELECT STAFF, DATE, PATIENT, COL4, COL5, COL6, COL7,CASE WHEN Col4='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col5='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col6='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col7='TRUE' THEN 1 ELSE 0 END AS SCORE,(CASE WHEN Col4='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col5='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col6='TRUE' THEN 1 ELSE 0 END +CASE WHEN Col7='TRUE' THEN 1 ELSE 0 END ) *100.0/4 AS PERCENTAGEFROM table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sqlslick
Yak Posting Veteran
83 Posts |
Posted - 2011-11-22 : 10:33:48
|
| Unbelievable! Excellent!! Thank you so much!!! The immediate response is very much appreciated!!!!Have a great day! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-22 : 10:48:09
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|