开发者

Need Help Creating An SSRS Report with Grouped Data

开发者 https://www.devze.com 2023-03-26 04:33 出处:网络
For simplicity sake, let\'s assume my DataSet looks like this: SELECT C.CategoryName, C.Description, P.ProductName, P.UnitPrice, P.ReorderLevel

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号