[英]Need Help Creating An SSRS Report with Grouped Data
For simplicity sake, let's assume my DataSet looks like this: 为了简单起见,我们假设我的DataSet如下所示:
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. 如果它们在两个不同的页面上,为什么不运行两个单独的查询并添加WHERE P.ProductName =“ something”,也可以执行GROUP BY获取不同的组,然后根据该结果集运行WHERE子句。
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.
我用一个List为CategoryId创建了一个组。 I then created a subreport which was passed the CategoryId as a parameter.
然后,我创建了一个子报表,该子报表已通过CategoryId作为参数传递。 Worked out well.
工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.