Create Microsoft SQL Report (SSRS) based on XML data stored in database

亡梦爱人 提交于 2019-12-05 15:09:35
Serge Belov

If the XML is stored in the DB and you can only access it through a SQL query, I'd suggest the following:

  1. Create an XML datasource with an empty connection string. Normally it'd be a Web site/service URL.
  2. In the report's dataset choose to use the XML data source. Note that the only possible command type is now Text.
  3. Add an internal parameter for the report, which would contain your XML file.
  4. Write an expression to get the default value for the parameter from the DB. The value should be your XML.
  5. In the dataset command use XML Query to select the fields, for example:

    <Query>
       <XmlData>
        <!-- Your XML starts -->
        <Books>
            <Book id='1'>Foo</Book>
            <Book id='2'>Bar</Book>
            <Book id='3'>Baz</Book>
        </Books>
        <!-- Your XML ends -->
       </XmlData>
       <ElementPath>Books/Book</ElementPath>
    </Query>
        <!--just tweaked indentation-->
    

This will add two fields: id and Book. You need to use the parameter instead of the XML.

UPDATE: Sorry for XML formatting, I cannot get code block to work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!