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.
| Author |
Topic |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-02-14 : 10:35:13
|
| I have a field in a sql table which is type bit (true or false)Here's my viewSELECT TOP (100) PERCENT ACC_Cause_C, COUNT(ACC_Cause_C) AS No_Incidents, SUM(ACC_NoDaysLost_B) AS [No days lost], ACC_Riddor_B AS [RIDDOR Reportable], ACC_PersonClassification_AFROM dbo.tblACC_AccidentReportGROUP BY ACC_Cause_C, ACC_PersonClassification_A, ACC_Riddor_BHAVING (ACC_PersonClassification_A = N'PCC Employee') AND (ACC_Riddor_B = 1)ORDER BY ACC_Cause_C, [RIDDOR Reportable]Against each ACC_Cause_C I want to count the number of ACC_Riiddor_B that are true. How can I do this ?end result wil be like thisCause No Incidents No dayslost RIDDOR ReportableRunning 8 10 3Walking 6 2 4 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-14 : 10:48:35
|
| SUM(CASE WHEN ACC_Riddor_B = 1 THEN 1 ELSE 0 END) as [RIDDOR Reportable], JimEveryday I learn something that somebody else already knew |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-02-14 : 10:50:23
|
| SUM(CAST ACC_Riddor_B AS INT)) AS RIDDOR Reportable--Gail ShawSQL Server MVP |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-02-14 : 11:09:18
|
| Thanks :-) |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-02-15 : 04:20:17
|
| My result is now showing as thisCause No Incidents No dayslost RIDDOR ReportableRunning 8 10 3Running 2 1 0Walking 6 2 4 Is there a way I can show Running as one line egRunning 10 11 3here's my ViewSELECT TOP (100) PERCENT ACC_Cause_C, COUNT(ACC_Cause_C) AS No_Incidents, SUM(ACC_NoDaysLost_B) AS [No days lost], SUM(CASE WHEN ACC_Riddor_B = 1 THEN 1 ELSE 0 END) AS [RIDDOR Reportable]FROM dbo.tblACC_AccidentReportGROUP BY ACC_Cause_C, ACC_PersonClassification_A, ACC_Riddor_BHAVING (ACC_PersonClassification_A = N'PCC Employee')ORDER BY ACC_Cause_C |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-02-15 : 04:41:11
|
| I've sorted it by basing another view on that view |
 |
|
|
|
|
|
|
|