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 |
|
rc1138
Starting Member
35 Posts |
Posted - 2010-05-06 : 23:21:49
|
| Hi All,Just having a really difficult time trying to count the number of activities per month for a whole year using an sql queryI'm trying to do just January and February for now to test it out w/o any luckHere is my statementSELECT (SELECT COUNT(MONTH(IncDate)) AS Expr1 FROM irIncident AS Jan WHERE (IncDate = I.IncDate) AND MONTH(1/1/1996) = 1) AS Jan, (SELECT COUNT(MONTH(IncDate)) AS Expr1 FROM irIncident AS Feb WHERE (IncDate = I.IncDate) AND MONTH(1/1/1996) = 1) AS Feb) AS FebFROM irIncident AS I INNER JOIN pdEmployee AS E ON I.EmpKey = E.EmpKeyWHERE (E.Department = '1000') AND (I.HlthCare = 'Y') I want it to display with just the total in one rowJanuary February 5 0 But it keeps displaying with multiple rows...January February2 02 03 03 0 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-05-06 : 23:33:14
|
you might want to include the Year else it will be counting all January for all the years.SELECT COUNT (CASE WHEN MONTH(IncDate) = 1 THEN 1 END) AS JAN, COUNT (CASE WHEN MONTH(IncDate) = 2 THEN 1 END) AS FEBFROM irIncident AS I INNER JOIN pdEmployee AS E ON I.EmpKey = E.EmpKeyWHERE E.Department = '1000'AND I.HlthCare = 'Y' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
rc1138
Starting Member
35 Posts |
Posted - 2010-05-06 : 23:41:01
|
| Awesome it works ! thanks so much |
 |
|
|
|
|
|