select city.name as City, group.name as [Group],
isnull(subqty.qty, 0) as Qty
from dbo.City
cross join dbo.Group
left outer join
(select cityid, groupid, count(*) as Qty
from dbo.User
where joindate >= @startdate
and joindate < @enddate
group by cityid, groupid) SubQty
on city.cityid = subqty.cityid
and group.groupid = subqty.groupid
order by city, group
Try that. (You'll need to format it to fit your needs, of course.)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon