简体   繁体   中英

Need Help Creating An SSRS Report with Grouped Data

For simplicity sake, let's assume my DataSet looks like this:

SELECT C.CategoryName, C.Description, P.ProductName, P.UnitPrice, P.ReorderLevel
FROM Categories C
JOIN Products P
ON P.CategoryID = C.CategoryID

And for simplicity let's say the data I get back looks like this:
BEVERAGES   | GREAT DRINKS | SODA     | 2.99 | 1
BEVERAGES   | GREAT DRINKS | VODKA    | 9.99 | 9
SNACKS      | GREAT SNACKS | PRETZELS | 1.99 | 1
SNACKS      | GREAT SNACKS | CHIPS    | 1.99 | 1

And let's say I want my report to look like this:

BEVERAGES - GREAT DRINKS


PRODUCT NAME      PRICE
VODKA             9.99
SODA              2.99

- PAGE BREAK -


SNACKS - GREAT SNACKS

PRODUCT NAME    | PRICE
PRETZELS        | 1.99
CHIPS           | 1.99

How would I go about doing this?

Are you wanting to run only one query?

If they are on two different pages, why not run two separate queries and adding a WHERE P.ProductName = "something" Or you could do a GROUP BY to get the different groups and run the WHERE clause according to that result set.

SELECT C.CategoryName, C.Description, P.ProductName AS pname, P.UnitPrice, P.ReorderLevel
FROM Categories C
JOIN Products P
ON P.CategoryID = C.CategoryID
ORDER BY P.ProductName

Psuedo Code

var hold = ''
foreach result as r
  if hold != r[pname] then call function to display product listing header
  hold = r[pname]
  display product information and pricing

It took some time, but basically I think I was trying to do a sub report. I used a List created a group for CategoryId. I then created a subreport which was passed the CategoryId as a parameter. Worked out well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM