<bdo id='QHfQG'></bdo><ul id='QHfQG'></ul>

    <i id='QHfQG'><tr id='QHfQG'><dt id='QHfQG'><q id='QHfQG'><span id='QHfQG'><b id='QHfQG'><form id='QHfQG'><ins id='QHfQG'></ins><ul id='QHfQG'></ul><sub id='QHfQG'></sub></form><legend id='QHfQG'></legend><bdo id='QHfQG'><pre id='QHfQG'><center id='QHfQG'></center></pre></bdo></b><th id='QHfQG'></th></span></q></dt></tr></i><div id='QHfQG'><tfoot id='QHfQG'></tfoot><dl id='QHfQG'><fieldset id='QHfQG'></fieldset></dl></div>

    <small id='QHfQG'></small><noframes id='QHfQG'>

  1. <legend id='QHfQG'><style id='QHfQG'><dir id='QHfQG'><q id='QHfQG'></q></dir></style></legend>
      <tfoot id='QHfQG'></tfoot>

      如何查询 SQL Server XML 列并返回特定节点的所有值

      时间:2023-06-05

          <bdo id='ts2ae'></bdo><ul id='ts2ae'></ul>
            <tbody id='ts2ae'></tbody>
          <legend id='ts2ae'><style id='ts2ae'><dir id='ts2ae'><q id='ts2ae'></q></dir></style></legend>

              • <tfoot id='ts2ae'></tfoot>

                <small id='ts2ae'></small><noframes id='ts2ae'>

              • <i id='ts2ae'><tr id='ts2ae'><dt id='ts2ae'><q id='ts2ae'><span id='ts2ae'><b id='ts2ae'><form id='ts2ae'><ins id='ts2ae'></ins><ul id='ts2ae'></ul><sub id='ts2ae'></sub></form><legend id='ts2ae'></legend><bdo id='ts2ae'><pre id='ts2ae'><center id='ts2ae'></center></pre></bdo></b><th id='ts2ae'></th></span></q></dt></tr></i><div id='ts2ae'><tfoot id='ts2ae'></tfoot><dl id='ts2ae'><fieldset id='ts2ae'></fieldset></dl></div>

                本文介绍了如何查询 SQL Server XML 列并返回特定节点的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我在 SQL Server 的 XML 列中有以下 XML.

                I have the following XML in a XML column in SQL Server.

                  <qualifiers>
                    <qualifier>
                      <key>111</key>
                      <message>a match was not found</message>
                    </qualifier>
                    <qualifier>
                      <key>222</key>
                      <message>a match was found</message>
                    </qualifier>
                    <qualifier>
                      <key>333</key>
                      <message>error</message>
                    </qualifier>
                  </qualifiers>
                

                如何编写 TSQL 以逗号分隔的字符串返回限定符/限定符/消息中的所有值?我的目标是让查询在每一行的单个列中返回 XML 中的值.

                How can I write TSQL to return all the values in qualifiers/qualifier/message in a comma delimited string? My goal is to have the query return the values from the XML in a single column for each row.

                结果应该是这样的:

                "a match was not found, a match was found, error"
                

                推荐答案

                SQLFiddle for相同:根据@xQbert 建议的解决方案

                SQLFiddle for the same: Solution as per @xQbert suggested

                create table Temp (col1 xml)
                go
                
                insert into Temp (col1)
                values('<qualifiers>
                    <qualifier>
                      <key>111</key>
                      <message>a match was not found</message>
                    </qualifier>
                    <qualifier>
                      <key>222</key>
                      <message>a match was found</message>
                    </qualifier>
                    <qualifier>
                      <key>333</key>
                      <message>error</message>
                    </qualifier>
                  </qualifiers>')
                go
                
                SELECT
                    STUFF((SELECT 
                              ',' + fd.v.value('(.)[1]', 'varchar(50)')
                           FROM 
                              Temp
                           CROSS APPLY
                              col1.nodes('/qualifiers/qualifier/message') AS fd(v)
                           FOR XML PATH('')
                          ), 1, 1, '')
                

                这篇关于如何查询 SQL Server XML 列并返回特定节点的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 SQLServer 2005 中查询 XML 列 下一篇:删除 SQL Server 中不同级别的空 XML 标记

                相关文章

                最新文章

                  <bdo id='sQz5p'></bdo><ul id='sQz5p'></ul>
              • <legend id='sQz5p'><style id='sQz5p'><dir id='sQz5p'><q id='sQz5p'></q></dir></style></legend>
                <tfoot id='sQz5p'></tfoot>

                  <small id='sQz5p'></small><noframes id='sQz5p'>

                    <i id='sQz5p'><tr id='sQz5p'><dt id='sQz5p'><q id='sQz5p'><span id='sQz5p'><b id='sQz5p'><form id='sQz5p'><ins id='sQz5p'></ins><ul id='sQz5p'></ul><sub id='sQz5p'></sub></form><legend id='sQz5p'></legend><bdo id='sQz5p'><pre id='sQz5p'><center id='sQz5p'></center></pre></bdo></b><th id='sQz5p'></th></span></q></dt></tr></i><div id='sQz5p'><tfoot id='sQz5p'></tfoot><dl id='sQz5p'><fieldset id='sQz5p'></fieldset></dl></div>