SSRS显示2个不同的细节

时间:2013-11-20 20:23:42

标签: sql reporting-services ssrs-grouping

我正在尝试创建一个ssrs报告,其中父组有两组不同的详细信息,我似乎无法弄清楚如何在父行下面显示唯一的详细信息

示例:

table1
master
master1
master2

table2
master,  hand
master1, hand1
master1, hand2
master2, hand1
master2, hand2

table3
master, foot
master1, foot1
master1, foot2
master2, foot1
master2, foot2

我的sql查询如下

select t1.master, t2.hand, t3.foot
from table1 t1 
left outer join table2 t2 on t1.master = t2.master
left outer join table2 t3 on t1.master = t3.master

我希望ssrs报告输出为

master1
hand1
hand2
foot1
foot2

master2
hand1
hand2
foot1
foot2
到目前为止,我已经能够获得

master1
hand1
hand2
master2
hand1
hand2

但是当我尝试添加另一行来显示脚时,它会链接到手牌而不是主手,所以它看起来像这样

master1
hand1
foot1
hand1
foot2
hand2
foot1
hand2
foot2

master2
hand1
foot1
hand1
foot2
hand2
foot1
hand2
foot2

如果我在分组之外添加另一行,它只显示table3的第一行

master1
hand1
hand2
foot1

master2
hand1
hand2
foot1

2 个答案:

答案 0 :(得分:2)

最好的办法是改变数据的结构。不是连接所有三个表,而是执行两个单独的查询(1个用于t2,1个用于t3)并将它们组合在一起,然后您可以按行获取数据并且更容易分组。您需要按tableName

对详细信息组进行排序
select t1.id, t2.detail, 't2' tableName from (
select 'master' id union
select 'master1' id union
select 'master2' id) t1
left outer join
(
select 'master' id,  'hand' detail union
select 'master1' id, 'hand1' detail union
select 'master1' id, 'hand2' detail union
select 'master2' id, 'hand1' detail union
select 'master2' id, 'hand2' detail )t2
on t1.id = t2.id

UNION

select t1.id, t3.detail, 't3' tableName from (
select 'master' id union
select 'master1' id union
select 'master2' id) t1
left outer join
(
select 'master' id, 'foot' detail union
select 'master1' id, 'foot1' detail union
select 'master1' id, 'foot2' detail union
select 'master2' id, 'foot1' detail union
select 'master2' id, 'foot2' detail)t3
on t1.id = t3.id

groupingExample2

结果是

Grouping result

答案 1 :(得分:2)

使用您的数据:

enter image description here

从基于master的{​​{1}}组和子组开始:

enter image description here

相邻群组添加到hand群组,但这一次在hand上分组:

enter image description here

enter image description here

Tablix现在看起来像这样:

enter image description here

这给出了所需的结果:

enter image description here