【问题标题】:SSRS: Can I display more than one table using the same dataset?SSRS:我可以使用同一个数据集显示多个表吗?
【发布时间】:2016-07-14 20:55:58
【问题描述】:

我有一个 HTML 格式的报告,根据组织的不同,它可以显示多个表格,这在 HTML 中相对容易。现在,我正在 SSRS 中编写相同的报告。

有没有一种方法可以让我使用类似中继器(如在 ASP.NET 中)的表可以重复,而单个表可以有自己的数据来显示。

我真的不知道从哪里开始。也许我可以有 10 个表指向类似的稍微修改过的数据集,并在没有数据时隐藏表。

感谢您的帮助

编辑

查询返回如下内容:

ID | Organization | Total | col1 | col2 | col3 | col4 | col5
-------------------------------------------------------------
1  | Accounting   | 10    | 2    | 1    | 3    | 0    |  4
-------------------------------------------------------------
2  | Production   | 15    | 7    | 0    | 3    | 1    |  4

现在报告应该是这样的

         Accounting
-------------------------------
| col1            | 2 (20.00%) |  
--------------------------------
| col2            | 1 (10.00%) |  
--------------------------------
| col3            | 3 (30.00%) |    
--------------------------------
| col4            | 0 (0.00%)  |   
--------------------------------
| col5            | 4 (40.00%) |     
--------------------------------

所以每行都会淹没一个表格。

【问题讨论】:

    标签: tsql ssrs-tablix


    【解决方案1】:

    这是可能的。

    假设您想为字段 A 中的每个值创建一个表,您可以使用字段 B-X 创建一个表,然后将此表放入另一个表的单元格中,该表使用相同的数据集并按字段进行行分组A. 这实质上将为您的每个子表提供一个过滤器。

    子表将自动调整为“超级表”中单元格的宽度和高度,但可以通过将子表放置在矩形内并放置矩形来避免(如果需要)进入超表。然后你会发现矩形可以调整大小,单元格的其余部分可以用其他矩形填充。

    要创建多个表格的外观,您可以玩转边框等,使超级表格不再可见。

    您提供的数据的 Xml(仅正文):

    <Body>
      <ReportItems>
        <Textbox Name="textbox1">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value>Report1</Value>
                  <Style>
                    <FontFamily>Tahoma</FontFamily>
                    <FontSize>20pt</FontSize>
                    <FontWeight>Bold</FontWeight>
                    <Color>SteelBlue</Color>
                  </Style>
                </TextRun>
              </TextRuns>
              <Style />
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>textbox1</rd:DefaultName>
          <Height>0.36in</Height>
          <Width>5in</Width>
          <Style>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
        <Tablix Name="Tablix2">
    <TablixBody>
      <TablixColumns>
        <TablixColumn>
          <Width>0.41667in</Width>
        </TablixColumn>
        <TablixColumn>
          <Width>2.19792in</Width>
        </TablixColumn>
        <TablixColumn>
          <Width>0.39583in</Width>
        </TablixColumn>
      </TablixColumns>
      <TablixRows>
        <TablixRow>
          <Height>0.25in</Height>
          <TablixCells>
            <TablixCell>
              <CellContents>
                <Textbox Name="Textbox29">
                  <CanGrow>true</CanGrow>
                  <KeepTogether>true</KeepTogether>
                  <Paragraphs>
                    <Paragraph>
                      <TextRuns>
                        <TextRun>
                          <Value />
                          <Style />
                        </TextRun>
                      </TextRuns>
                      <Style />
                    </Paragraph>
                  </Paragraphs>
                  <rd:DefaultName>Textbox29</rd:DefaultName>
                  <Style>
                    <Border>
                      <Style>None</Style>
                    </Border>
                    <PaddingLeft>2pt</PaddingLeft>
                    <PaddingRight>2pt</PaddingRight>
                    <PaddingTop>2pt</PaddingTop>
                    <PaddingBottom>2pt</PaddingBottom>
                  </Style>
                </Textbox>
              </CellContents>
            </TablixCell>
            <TablixCell>
              <CellContents>
                <Textbox Name="Textbox31">
                  <CanGrow>true</CanGrow>
                  <KeepTogether>true</KeepTogether>
                  <Paragraphs>
                    <Paragraph>
                      <TextRuns>
                        <TextRun>
                          <Value />
                          <Style />
                        </TextRun>
                      </TextRuns>
                      <Style />
                    </Paragraph>
                  </Paragraphs>
                  <rd:DefaultName>Textbox31</rd:DefaultName>
                  <Style>
                    <Border>
                      <Color>LightGrey</Color>
                      <Style>None</Style>
                    </Border>
                    <PaddingLeft>2pt</PaddingLeft>
                    <PaddingRight>2pt</PaddingRight>
                    <PaddingTop>2pt</PaddingTop>
                    <PaddingBottom>2pt</PaddingBottom>
                  </Style>
                </Textbox>
              </CellContents>
            </TablixCell>
            <TablixCell>
              <CellContents>
                <Textbox Name="Textbox35">
                  <CanGrow>true</CanGrow>
                  <KeepTogether>true</KeepTogether>
                  <Paragraphs>
                    <Paragraph>
                      <TextRuns>
                        <TextRun>
                          <Value />
                          <Style />
                        </TextRun>
                      </TextRuns>
                      <Style />
                    </Paragraph>
                  </Paragraphs>
                  <rd:DefaultName>Textbox35</rd:DefaultName>
                  <Style>
                    <Border>
                      <Color>LightGrey</Color>
                      <Style>None</Style>
                    </Border>
                    <PaddingLeft>2pt</PaddingLeft>
                    <PaddingRight>2pt</PaddingRight>
                    <PaddingTop>2pt</PaddingTop>
                    <PaddingBottom>2pt</PaddingBottom>
                  </Style>
                </Textbox>
              </CellContents>
            </TablixCell>
          </TablixCells>
        </TablixRow>
        <TablixRow>
          <Height>1.41667in</Height>
          <TablixCells>
    <TablixCell>
      <CellContents>
        <Textbox Name="Organization">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value />
                  <Style />
                </TextRun>
              </TextRuns>
              <Style />
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>Organization</rd:DefaultName>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
      </CellContents>
    </TablixCell>
    <TablixCell>
      <CellContents>
        <Tablix Name="Tablix1">
          <TablixBody>
            <TablixColumns>
              <TablixColumn>
                <Width>1.09896in</Width>
              </TablixColumn>
              <TablixColumn>
                <Width>1.09896in</Width>
              </TablixColumn>
            </TablixColumns>
            <TablixRows>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="Organization1">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!Organization.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style>
                              <TextAlign>Center</TextAlign>
                            </Style>
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>Organization1</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                      <ColSpan>2</ColSpan>
                    </CellContents>
                  </TablixCell>
                  <TablixCell />
                </TablixCells>
              </TablixRow>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col1">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>col1</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col1</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col6">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!col1.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col1</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                </TablixCells>
              </TablixRow>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col2">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>col2</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col2</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col21">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!col2.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col21</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                </TablixCells>
              </TablixRow>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col3">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>col3</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col3</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col31">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!col3.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col31</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                </TablixCells>
              </TablixRow>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col4">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>col4</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col4</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="Textbox15">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!col4.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>Textbox15</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                </TablixCells>
              </TablixRow>
              <TablixRow>
                <Height>0.23611in</Height>
                <TablixCells>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="col5">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>col5</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>col5</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                  <TablixCell>
                    <CellContents>
                      <Textbox Name="Textbox18">
                        <CanGrow>true</CanGrow>
                        <KeepTogether>true</KeepTogether>
                        <Paragraphs>
                          <Paragraph>
                            <TextRuns>
                              <TextRun>
                                <Value>=Fields!col5.Value</Value>
                                <Style />
                              </TextRun>
                            </TextRuns>
                            <Style />
                          </Paragraph>
                        </Paragraphs>
                        <rd:DefaultName>Textbox18</rd:DefaultName>
                        <Style>
                          <Border>
                            <Color>LightGrey</Color>
                            <Style>Solid</Style>
                          </Border>
                          <PaddingLeft>2pt</PaddingLeft>
                          <PaddingRight>2pt</PaddingRight>
                          <PaddingTop>2pt</PaddingTop>
                          <PaddingBottom>2pt</PaddingBottom>
                        </Style>
                      </Textbox>
                    </CellContents>
                  </TablixCell>
                </TablixCells>
              </TablixRow>
            </TablixRows>
          </TablixBody>
          <TablixColumnHierarchy>
            <TablixMembers>
              <TablixMember />
              <TablixMember />
            </TablixMembers>
          </TablixColumnHierarchy>
          <TablixRowHierarchy>
            <TablixMembers>
              <TablixMember />
              <TablixMember />
              <TablixMember />
              <TablixMember />
              <TablixMember />
              <TablixMember />
            </TablixMembers>
          </TablixRowHierarchy>
          <DataSetName>DataSet1</DataSetName>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
          </Style>
        </Tablix>
      </CellContents>
    </TablixCell>
            <TablixCell>
              <CellContents>
                <Textbox Name="Textbox36">
                  <CanGrow>true</CanGrow>
                  <KeepTogether>true</KeepTogether>
                  <Paragraphs>
                    <Paragraph>
                      <TextRuns>
                        <TextRun>
                          <Value />
                          <Style />
                        </TextRun>
                      </TextRuns>
                      <Style />
                    </Paragraph>
                  </Paragraphs>
                  <rd:DefaultName>Textbox36</rd:DefaultName>
                  <Style>
                    <Border>
                      <Style>None</Style>
                    </Border>
                    <PaddingLeft>2pt</PaddingLeft>
                    <PaddingRight>2pt</PaddingRight>
                    <PaddingTop>2pt</PaddingTop>
                    <PaddingBottom>2pt</PaddingBottom>
                  </Style>
                </Textbox>
              </CellContents>
            </TablixCell>
          </TablixCells>
        </TablixRow>
      </TablixRows>
    </TablixBody>
          <TablixColumnHierarchy>
            <TablixMembers>
              <TablixMember />
              <TablixMember />
              <TablixMember />
            </TablixMembers>
          </TablixColumnHierarchy>
          <TablixRowHierarchy>
            <TablixMembers>
              <TablixMember>
                <KeepWithGroup>After</KeepWithGroup>
              </TablixMember>
              <TablixMember>
                <Group Name="Details">
                  <GroupExpressions>
                    <GroupExpression>=Fields!Organization.Value</GroupExpression>
                  </GroupExpressions>
                </Group>
              </TablixMember>
            </TablixMembers>
          </TablixRowHierarchy>
          <DataSetName>DataSet1</DataSetName>
          <Top>0.36in</Top>
          <Height>1.66667in</Height>
          <Width>3.01042in</Width>
          <ZIndex>1</ZIndex>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
          </Style>
        </Tablix>
      </ReportItems>
      <Height>3.69667in</Height>
      <Style />
    </Body>
    

    数据集是:

    <DataSets>
      <DataSet Name="DataSet1">
        <Query>
          <DataSourceName>DataSource1</DataSourceName>
          <CommandText>SELECT        1 AS ID, 'Accounting' AS Organization, 10 AS Total, 2 AS col1, 1 AS col2, 3 AS col3, 0 AS col4, 4 AS col5
    UNION ALL
    SELECT        2 AS Expr1, 'Production' AS Expr2, 15 AS Expr3, 7 AS Expr4, 0 AS Expr5, 3 AS Expr6, 1 AS Expr7, 4 AS Expr8</CommandText>
        </Query>
        <Fields>
          <Field Name="ID">
            <DataField>ID</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="Organization">
            <DataField>Organization</DataField>
            <rd:TypeName>System.String</rd:TypeName>
          </Field>
          <Field Name="Total">
            <DataField>Total</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="col1">
            <DataField>col1</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="col2">
            <DataField>col2</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="col3">
            <DataField>col3</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="col4">
            <DataField>col4</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="col5">
            <DataField>col5</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
        </Fields>
      </DataSet>
    </DataSets>
    

    【讨论】:

    • 请查看我认为有助于描绘最终结果的补充信息。
    • 所以字段 A 将是您的“组织”字段,您将使用另一个字段“col1”等构建子表,然后将其添加到超级行分组中-桌子。我在我的答案中添加了一些 xml 来构建你的输出。
    【解决方案2】:

    我会为这个任务unpivot,如下面的脚本:

    --Create the table and insert values as portrayed in the previous example.
    CREATE TABLE pvt (VendorID int, Emp1 int, Emp2 int,
        Emp3 int, Emp4 int, Emp5 int);
    GO
    INSERT INTO pvt VALUES (1,4,3,5,4,4);
    INSERT INTO pvt VALUES (2,4,1,5,5,5);
    INSERT INTO pvt VALUES (3,4,3,5,4,4);
    INSERT INTO pvt VALUES (4,4,2,5,5,4);
    INSERT INTO pvt VALUES (5,5,1,5,5,5);
    GO
    
    SELECT * FROM pvt
    --Unpivot the table.
    SELECT VendorID, Employee, Orders
    FROM 
       (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5
       FROM pvt) p
    UNPIVOT
       (Orders FOR Employee IN 
          (Emp1, Emp2, Emp3, Emp4, Emp5)
    )AS unpvt;
    GO
    

    发件人:https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      相关资源
      最近更新 更多