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 |
Karen426
Starting Member
3 Posts |
Posted - 2012-05-31 : 16:21:48
|
I need to count the number of rings in a region. My query does that but this is for an SSRS report so when I run the report I want it to display a 0 where there is no rings in that regionbut currently I am only getting regions where the count is greater or equal to 1select plantype, planyear, region, Case When count(ring) < 1 then 0 else count(ring) End as ringcntFrom Awhere planyear > 2011group byplantype, planyear, regionCurrently my data displays asA 2012 Central 12 Northeast 4I want it to display as A 2012 Central 12 South 0 Northeast 4 West 0Thanks ahead for helping me |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-31 : 18:02:09
|
quote: Originally posted by Karen426 I need to count the number of rings in a region. My query does that but this is for an SSRS report so when I run the report I want it to display a 0 where there is no rings in that regionbut currently I am only getting regions where the count is greater or equal to 1select plantype, planyear, region, Case When count(ring) < 1 then 0 else count(ring) End as ringcntFrom Awhere planyear > 2011group byplantype, planyear, regionCurrently my data displays asA 2012 Central 12 Northeast 4I want it to display as A 2012 Central 12 South 0 Northeast 4 West 0Thanks ahead for helping me
select t.plantype,t.planyear,t.region, count(ring) as ringcntfrom(select plantype,planyear,regionfrom (select distinct plantype,planyear from A)mcross join (select distinct region from A)n)tleft join A aon a.plantype = t.plantypeand a.planyear = t.planyearand a.region = t.regiongroup by t.plantype,t.planyear,t.region ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|