繁体   English   中英

SSRS矩阵显示层次结构

[英]SSRS matrix show hierarchy

我正在处理一个报告,其中必须显示具有6级子层次结构的类别。

简而言之:多个类别,每个类别都有多个属性,这些属性中的每个可以具有多个子属性,这些子属性可以具有子属性,依此类推。

select语句的结果如下所示:

ModellID | ModellName| ParentLevelID | LevelID | LevelName | ParentAttributeID | AttributeID | AttributeName

该报告应如下所示:

             Level 1       Level 2   Level 3   Level 4 ...
Modell A | Attribute A | Child A | Child A |         |
         |             |         | Child B | Child A |
         |             |         |         | Child B |
         |             | Child B | Child A |         |
         | Attribute B | Child A |         |         |
         | Attribute C | Child A | Child A |         |
         |             |         | Child B |         |
         |             |         | Child C |         |
         |             | Child B | Child A |         |
Modell B | Attribute A | Child A | Child A | Child A |
         |             |         |         | Child B |

我试图创建一个矩阵,其中类别为行组,级别为列组,属性为值,但这仅显示每个类别的第一条记录。

我也尝试了在google的帮助下找到的多个建议,但是我无法使它们起作用。

任何帮助或建议,我们将不胜感激!

示例数据:

Create Table hierarchy_ssrs (
    ModellID uniqueidentifier,
    ModellName varchar(max),
    ParentLevelID uniqueidentifier,
    LevelID uniqueidentifier,
    LevelName varchar(max),
    ParentAttributeID uniqueidentifier,
    AttributeID uniqueidentifier,
    AttributeName varchar(max)
)

https://dl.dropboxusercontent.com/u/108638325/Example_Data.xlsx

您可以通过SQL Management Studio导入数据。 右键单击数据库->任务->导入数据->数据源:MS Excel->浏览文件-> ...进一步的步骤应该是不言自明的。

提前致谢!

我找到了解决问题的方法。

对于数据集,我使用了一条select语句,并将表与自身多次连接。 在报表构建器中,我使用select语句列作为表中的列创建了一个表。 之后,我为每列创建一个行分组,并删除了相应的旧列。

这是select语句的sql代码。

select hs1.ModellName as Modell, 
    hs1.AttributeName as [Level 1],
    hs2.AttributeName as [Level 2],
    hs3.AttributeName as [Level 3],
    hs4.AttributeName as [Level 4],
    hs5.AttributeName as [Level 5],
    hs6.AttributeName as [Level 6]
from hierarchy_ssrs hs1
    left join hierarchy_ssrs hs2 on hs2.ParentAttributeID = hs1.AttributeID
    left join hierarchy_ssrs hs3 on hs3.ParentAttributeID = hs2.AttributeID
    left join hierarchy_ssrs hs4 on hs4.ParentAttributeID = hs3.AttributeID
    left join hierarchy_ssrs hs5 on hs5.ParentAttributeID = hs4.AttributeID
    left join hierarchy_ssrs hs6 on hs6.ParentAttributeID = hs5.AttributeID
where hs.ParentAttributeID is null
order by Modell,
    LevelName,
    [Level 1],
    [Level 2],
    [Level 3],
    [Level 4],
    [Level 5],
    [Level 6]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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