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

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

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

    2. <legend id='NMIZD'><style id='NMIZD'><dir id='NMIZD'><q id='NMIZD'></q></dir></style></legend>

      使用 Any(,) 分隔符在单列中检索的 XML 值 (2)

      时间:2023-06-07
    3. <legend id='5L6B9'><style id='5L6B9'><dir id='5L6B9'><q id='5L6B9'></q></dir></style></legend>
      <i id='5L6B9'><tr id='5L6B9'><dt id='5L6B9'><q id='5L6B9'><span id='5L6B9'><b id='5L6B9'><form id='5L6B9'><ins id='5L6B9'></ins><ul id='5L6B9'></ul><sub id='5L6B9'></sub></form><legend id='5L6B9'></legend><bdo id='5L6B9'><pre id='5L6B9'><center id='5L6B9'></center></pre></bdo></b><th id='5L6B9'></th></span></q></dt></tr></i><div id='5L6B9'><tfoot id='5L6B9'></tfoot><dl id='5L6B9'><fieldset id='5L6B9'></fieldset></dl></div>

      <small id='5L6B9'></small><noframes id='5L6B9'>

            <tbody id='5L6B9'></tbody>
            <bdo id='5L6B9'></bdo><ul id='5L6B9'></ul>

              • <tfoot id='5L6B9'></tfoot>
              • 本文介绍了使用 Any(,) 分隔符在单列中检索的 XML 值 (2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..
                declare @x xml =
                '<Detials xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <Tests>
                  <Test Name="Test1" TotalMarks="100">95</Test>
                  <Test Name="Test2" TotalMarks="200">65</Test>
                  <Test Name="Test3" TotalMarks="150">95</Test>
                  <Test Name="Test4" TotalMarks="150"></Test>
                   </Tests>
                   <Tests>
                  <Test Name="Test1" TotalMarks="100">95</Test>
                  <Test Name="Test2" TotalMarks="200">65</Test>
                  <Test Name="Test3" TotalMarks="150">95</Test>
                  <Test Name="Test4" TotalMarks="150"></Test>
                    </Tests>
                </Detials>'
                

                当我这样查询时

                SELECT STUFF(
                    @x.query('for $a in (*:Detials/Tests/Test/@Name) 
                        return <a>{concat(",", $a)}</a>')
                    .value('.', 'NVARCHAR(MAX)'), 
                    1, 1, '') AS ListOfName
                

                我是这样的

                名称列表
                测试 1、测试 2、测试 3、测试 4、测试 1、测试 2、测试 3、测试 4

                ListofName
                Test1,Test2,Test3,Test4,Test1,Test2,Test3,Test4

                但是想要根据 <Test> 粉碎 xml,这可以给出如下结果

                But Want to shred the xml based on the <Test> Which can give the result like this below

                名称列表
                测试1、测试2、测试3、测试4
                测试1、测试2、测试3、测试4

                ListofName
                Test1,Test2,Test3,Test4
                Test1,Test2,Test3,Test4

                请在这里帮助我在使用 query() 和 value() 进行字符串连接之前将原始 XML 分解为单独的行

                Please help me here to shred original XML into separate rows before string concatenation with query() and value()

                提前致谢,Jayendran

                Thanks in Advance ,Jayendran

                推荐答案

                试试这个解决方案:

                declare @x xml =
                '<Detials xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <Tests>
                  <Test Name="Test1" TotalMarks="100">95</Test>
                  <Test Name="Test2" TotalMarks="200">65</Test>
                  <Test Name="Test3" TotalMarks="150">95</Test>
                  <Test Name="Test4" TotalMarks="150"></Test>
                   </Tests>
                   <Tests>
                  <Test Name="Test1" TotalMarks="100">95</Test>
                  <Test Name="Test2" TotalMarks="200">65</Test>
                  <Test Name="Test3" TotalMarks="150">95</Test>
                  <Test Name="Test4" TotalMarks="150"></Test>
                    </Tests>
                </Detials>'
                
                -- Edit 1
                SELECT  XmlTable.OriginalID, ROW_NUMBER() OVER(ORDER BY x.XmlCol) AS RowNum, y.ListOfName
                FROM (SELECT 1 AS OriginalID, @x AS XmlCol) AS XmlTable -- Edit 2
                CROSS APPLY XMLTable.XmlCol.nodes('*:Detials/Tests') AS x(XmlCol)
                CROSS APPLY(
                    SELECT STUFF(x.XmlCol.query('for $a in (Test/@Name) return <a>{concat(",", $a)}</a>').value('.', 'NVARCHAR(MAX)'), 1, 1, '')
                ) AS y(ListOfName)
                -- End of Edit 1
                

                演示

                这篇关于使用 Any(,) 分隔符在单列中检索的 XML 值 (2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:从父节点 xml sql server 检索所有子节点 下一篇:FOR XML PATH 导致 SSMS 被截断为 2034 个字符

                相关文章

                最新文章

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

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

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

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