首页 文章

是否可以在SSRS报表设计器中使用XML数据集

提问于
浏览
0

是否可以在SSRS报表设计器中使用XML数据集?我需要获取一个大数据集,如,

Master Row
  - Details1
  - Details2
  - ... DetailsN

我已经创建了使用 FOR XML RAW 返回XML数据的查询,但在添加新报表时我无法在查询设计器中使用它 .

请注意我没有使用XML数据源,我只是尝试使用SELECT查询添加XML数据集 . 我没有尝试过存储过程,但不确定它是否也能正常工作......

In other words, is it possible to add a XML dataset (Not datasource) to SSRS reports

1 回答

  • 0

    如果您需要一个看起来像树视图的XML,您可能会执行以下操作:

    DECLARE @xml XML=
    '<root>
      <level content="Level A">
        <detail content="Detail AA">
          <item content="item AAA" />
        </detail>
        <detail content="Detail AB">
          <item content="item ABA" />
          <item content="item ABB" />
          <item content="item ABC" />
        </detail>
        <detail content="Detail AC">
          <item content="item ACA" />
          <item content="item ACB" />
        </detail>
      </level>
      <level content="Level B">
        <detail content="Detail BA">
          <item content="item BAA" />
        </detail>
        <detail content="Detail BB">
          <item content="item BBA" />
          <item content="item BBB" />
          <item content="item BBC" />
        </detail>
        <detail content="Detail BC">
          <item content="item BCA" />
          <item content="item BCB" />
        </detail>
      </level>
    </root>';
    
    
    SELECT  CASE The.Node.value('fn:local-name(.)','varchar(max)')
            WHEN 'level' THEN ''
            WHEN 'detail' THEN REPLICATE(' ',4)
            WHEN 'item' THEN REPLICATE(' ',8)
            ELSE ''
            END + The.Node.value('@content','varchar(max)')
    FROM @xml.nodes('root//*') AS The(Node)
    

    结果

    Level A
        Detail AA
            item AAA
        Detail AB
            item ABA
            item ABB
            item ABC
        Detail AC
            item ACA
            item ACB
    Level B
        Detail BA
            item BAA
        Detail BB
            item BBA
            item BBB
            item BBC
        Detail BC
            item BCA
            item BCB
    

相关问题