SSRS:解析具有 XML 列的 SQL Server 查询的结果

发布于 2024-10-26 20:30:22 字数 1133 浏览 2 评论 0原文

我正在查看以下查询:

SELECT  txt.ID, txt.Rev, txt.Words,
        flds.ReferenceName
FROM    Fields flds (NOLOCK) 
        JOIN WorkItemLongTexts txt (NOLOCK) 
            ON flds.FldID = txt.FldID
WHERE   flds.ReferenceName = 'Microsoft.VSTS.TCM.Steps'

第三列 (txt.Words) 返回此值:

<steps id="0" last="3">
  <step id="1" type="ValidateStep">
    <parameterizedString>
      <text>Step 1</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 1</text>
    </parameterizedString>
    <description />
  </step>
  <step id="2" type="ValidateStep">
    <parameterizedString>
      <text>Step 2</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 2</text>
    </parameterizedString>
    <description />
  </step>      
</steps>

显然,我可以使用 .net 客户端应用程序轻松解析此值。但是,我想将此查询直接放入 SSRS 报告中。

有没有办法将此列中的数据放入 SSRS 可使用的数据集中,如下所示:
1 |验证步骤 |步骤 1 |结果1
2 |验证步骤 |步骤 2 |结果 2

(或类似结果)

I am looking at the following query:

SELECT  txt.ID, txt.Rev, txt.Words,
        flds.ReferenceName
FROM    Fields flds (NOLOCK) 
        JOIN WorkItemLongTexts txt (NOLOCK) 
            ON flds.FldID = txt.FldID
WHERE   flds.ReferenceName = 'Microsoft.VSTS.TCM.Steps'

The third column (txt.Words) returns this value:

<steps id="0" last="3">
  <step id="1" type="ValidateStep">
    <parameterizedString>
      <text>Step 1</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 1</text>
    </parameterizedString>
    <description />
  </step>
  <step id="2" type="ValidateStep">
    <parameterizedString>
      <text>Step 2</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 2</text>
    </parameterizedString>
    <description />
  </step>      
</steps>

Clearly I can easily parse this out with a .net client side application. However, I would like to take this query directly into a SSRS report.

Is there a way to get the data from this column into a SSRS consumable dataset like this:
1 | ValidateStep | Step 1 | Result 1
2 | ValidateStep | Step 2 | Result 2

(or anything similar)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆° 2024-11-02 20:30:22

您可以使用 TSQL 的 OpenXML 功能从 xml 数据获取行集,但是您想要元素和属性的组合,因此这将是一个小工作。

You can use TSQL's OpenXML functionality to get a rowset from your xml data, however you want a combination of elements and attributes so it will be a little work.

凉城 2024-11-02 20:30:22

我对 ssrs 一无所知,但以下是我在常规查询中的做法。也许它是你可以使用的东西。
我已经简化了您的示例并使用表变量。我假设 XMLColumn 的数据类型为 xml

-- Sample table
declare @T table (ID int, XMLColumn xml)

-- Insert sample data
insert into @T values
(1,'
<steps id="0" last="3">
  <step id="1" type="ValidateStep">
    <parameterizedString>
      <text>Step 1</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 1</text>
    </parameterizedString>
    <description />
  </step>
  <step id="2" type="ValidateStep">
    <parameterizedString>
      <text>Step 2</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 2</text>
    </parameterizedString>
    <description />
  </step>      
</steps>')

-- Duplcate first row
insert into @T 
select 2, XMLColumn
from @T


-- The query
select
  ID as RowID,
  s.value('@id', 'int') as ID, 
  s.value('@type', 'varchar(15)') as [Type],
  s.value('parameterizedString[1]/text[1]', 'varchar(15)') as Step, 
  s.value('parameterizedString[2]/text[1]', 'varchar(15)') as Result 
from @T

结果

RowID       ID          Type            Step            Result
----------- ----------- --------------- --------------- ---------------
1           1           ValidateStep    Step 1          Result 1
1           2           ValidateStep    Step 2          Result 2
2           1           ValidateStep    Step 1          Result 1
2           2           ValidateStep    Step 2          Result 2

I don't know anything about ssrs but here is how I would do it in a regular query. Perhaps it is something you can use.
I have simplified your sample and uses a table variable instead. I assume that the XMLColumn has datatype xml.

-- Sample table
declare @T table (ID int, XMLColumn xml)

-- Insert sample data
insert into @T values
(1,'
<steps id="0" last="3">
  <step id="1" type="ValidateStep">
    <parameterizedString>
      <text>Step 1</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 1</text>
    </parameterizedString>
    <description />
  </step>
  <step id="2" type="ValidateStep">
    <parameterizedString>
      <text>Step 2</text>
    </parameterizedString>
    <parameterizedString>
      <text>Result 2</text>
    </parameterizedString>
    <description />
  </step>      
</steps>')

-- Duplcate first row
insert into @T 
select 2, XMLColumn
from @T


-- The query
select
  ID as RowID,
  s.value('@id', 'int') as ID, 
  s.value('@type', 'varchar(15)') as [Type],
  s.value('parameterizedString[1]/text[1]', 'varchar(15)') as Step, 
  s.value('parameterizedString[2]/text[1]', 'varchar(15)') as Result 
from @T

Result

RowID       ID          Type            Step            Result
----------- ----------- --------------- --------------- ---------------
1           1           ValidateStep    Step 1          Result 1
1           2           ValidateStep    Step 2          Result 2
2           1           ValidateStep    Step 1          Result 1
2           2           ValidateStep    Step 2          Result 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文