2013-09-05 132 views
0

我正在研究一個報告,我必須顯示具有6級子級別的類別。SSRS矩陣顯示層次結構

說得更容易理解: 多個類別,每個類別都有多個屬性,每個屬性可以有多個子屬性,這些子屬性可以有子屬性等等。

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 - >瀏覽文件 - > ...進一步的步驟應該是不言自明的。

在此先感謝!

+0

您能否提供一個簡化的示例數據集和您期望的最終結果,以幫助證明您的要求? –

+0

添加了一個帶有示例數據和表定義的excel文檔。最終結果應該看起來像在每個屬性和模型上展開圖標的問題。 – bego

+0

對不起,該文件沒有正確上傳,現在示例數據應該是正確的。 – bego

回答

0

我找到了解決我的問題的方法。

爲數據集我用一個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]