Monday, March 19, 2012

Joining summary data with detail data

I know similar questions have been asked but I wanted to try my luck that my issue is somehow different.

I am querying a database which has detail information (sales transactions) and is grouped by customer. I also have a table with one record for each customer with some historical sales information (summary information). The requirements for the report are to have the sums of the sales for each customer along with the historical data for that customer in the same row in the table. I haven't found a way to do this using one dataset and from what I've read, the current version doesn't support joining multiple datasets over a grouping field (customer).. or at all.

Any one have ideas?

In an ideal world, you would think that you could use SSRS to create the summary information from the detail information. That being said, I have a similar situation where the summary data is not exactly the same information. My summary data is counts by month of eligible accounts. The detail is counts of various rewards by month. I end up having information that looks like

Jan Feb Mar Apr May Jun
Elig 10 12 10 11 8 15
Reward 1 2 1 3 4 1 0
Reward 2 3 3 2 3 2 3
Reward 3 4 1 2 1 0 4

The way I did this was to use a UNION query with constants into a matrix report.

SELECT 0 'Level', 'Elig' Reward, Month, count(*) amt from SummaryTable Group By 1,2,3
UNION
SELECT 1 'Level', Reward, Month, count(*) amt from DetailTable Group By 1,2,3
Order by 1,2,3;

This way the Eligible data (SUMMARY) was at the top and the detail followed.

R

No comments:

Post a Comment