如何将动态数据透视表结果添加到SSRS报告中?

mar*_*mer 4 sql t-sql pivot reporting-services

我是Pivot和SSRS的新手,我需要创建一个类似于Pivot Table的报告.

报告布局如下:

           Area_1  Area_2  Area_3  Area_4  ...  Area_N
A_Percent
B_Percent
C_Percent
D_Percent
Run Code Online (Sandbox Code Playgroud)

由于"Area_N"是动态的,因此我的表格布局如下:

Area   A_Percent   B_Percent   C_Percent   D_Percent
----   ---------   ---------   ---------   ---------
Area_1    45           55         66           77
Area_2    22           33         11           55 
Area_3    12           45         88           36
Area_4    67           23         37           28
...
Area_N    76           67         35           28
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

  1. 如何基于上述结构创建Pivot表?
  2. 我的SSRS报告可以从数据透视表中读取数据吗?

欢迎所有大师评论.非常感谢!

Cha*_*leh 14

首先 - 您可以在SSRS 2005(或更高版本的Tablix)中使用Matrix,它将为您提供所需的内容.但是,你遇到的问题是矩阵在垂直格式中的效果更好.所以在你的情况下你需要像这样查询:

SELECT Area, 'A_Percent' as Type, A_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'B_Percent' as Type, B_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'C_Percent' as Type, C_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'D_Percent' as Type, D_Percent as Val FROM YourTable
Run Code Online (Sandbox Code Playgroud)

那么你应该有一个看起来更像这样的结果集:

Area    Type       Value
Area_1    A_Percent  50
Area_2    A_Percent  42
Area_3    A_Percent  20
Area_1    B_Percent  12
Area_2    B_Percent  28
Area_3    B_Percent  16
Run Code Online (Sandbox Code Playgroud)

现在您可以在Matrix控件中使用它.将"区域"字段拖放到"列"组中.将Type字段拖放到'rows'组中并将Value放入中间(将转换为SUM()表达式)

设计师

例...

全部完成 :)