【问题标题】:SSRS matrix show hierarchySSRS 矩阵显示层次结构
【发布时间】:2013-09-05 14:05:18
【问题描述】:

我正在编写一份报告,我必须在其中显示具有 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 |

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

我还尝试了在谷歌的帮助下找到的多个建议,但我无法让它们发挥作用。

非常感谢任何帮助或建议!

示例数据:

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 -> 浏览文件 -> ...进一步的步骤应该是不言自明的。

提前致谢!

【问题讨论】:

  • 您能否提供一个简化的示例数据集以及基于此的您想要的最终结果,以帮助展示您的需求?
  • 添加了一个带有示例数据和表格定义的 Excel 文档。最终结果应该看起来像问题中的每个属性和模型上都有展开图标。
  • 很抱歉文件没有正确上传,现在示例数据应该是正确的。

标签: tsql view reporting-services tree hierarchy


【解决方案1】:

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

对于数据集,我使用了一个 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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    相关资源
    最近更新 更多