Reporting on data when data is missing (ie. how to report zero activities for a customer on a given

Posted by Christian Vik on Stack Overflow See other posts from Stack Overflow or by Christian Vik
Published on 2010-04-12T11:22:30Z Indexed on 2010/04/12 11:23 UTC
Read the original article Hit count: 406

I want to create a report which aggregates the number of activities per customer per week. If there has been no activites on that customer for a given week, 0 should be displayed (i.e week 3 and 4 in the sample below)

CUSTOMER | #ACTIVITIES | WEEKNUMBER
A | 4 | 1
A | 2 | 2
A | 0 | 3
A | 0 | 4
A | 1 | 5
B ...
C ...

The problem is that if there are no activities there is no data to report on and therefor week 3 and 4 in the sample below is not in the report.

What is the "best" way to solve this?

© Stack Overflow or respective owner

Related posts about sql-server-2008

Related posts about sql-server