<bdo id='4N2t2'></bdo><ul id='4N2t2'></ul>

      <legend id='4N2t2'><style id='4N2t2'><dir id='4N2t2'><q id='4N2t2'></q></dir></style></legend>
    1. <small id='4N2t2'></small><noframes id='4N2t2'>

    2. <tfoot id='4N2t2'></tfoot>

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

      1. 在 T-SQL 中通过 XQuery 选择时连接 xml 值

        时间:2023-06-07

            1. <tfoot id='x6oSj'></tfoot>
                <bdo id='x6oSj'></bdo><ul id='x6oSj'></ul>

                  <tbody id='x6oSj'></tbody>
              • <small id='x6oSj'></small><noframes id='x6oSj'>

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

                  本文介绍了在 T-SQL 中通过 XQuery 选择时连接 xml 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这是我的示例 XML:

                  This is my sample XML:

                  <root>
                      <element>
                          <subelement>
                              <value code="code1">value1</value>
                              <value code="code2">value2</value>
                          </subelement>
                      </element>
                  </root>
                  

                  这是我的测试查询:

                  DECLARE @tempTable TABLE (
                      ValueCode nvarchar(MAX),
                      Value nvarchar(MAX)
                  )
                  
                  DECLARE @xml XML
                  select @xml = cast(c1 as xml) from OPENROWSET (BULK 'C:\test.xml', SINGLE_BLOB) as T1(c1)
                  
                  INSERT INTO @tempTable
                  SELECT 
                      Tbl.Col.value('subelement[1]/@code', 'NVARCHAR(MAX)'),
                      Tbl.Col.value('subelement[1]', 'NVARCHAR(MAX)')
                  FROM @xml.nodes('//element') Tbl(Col)
                  
                  SELECT * FROM @tempTable
                  

                  查询在执行时给出一行,其中 ValueCode 列包含 NULL,Value 列包含value1value2".我想得到的是用分隔符连接的属性和值.例如,我需要 ValueCode 来包含 'code1;code2' 和 Value 包含 'value 1;值2'.我怎样才能做到这一点?

                  The query, when executed, gives out a row with the ValueCode column containing NULL and the Value column containing 'value1value2'. What I would like to get would be the attributes and values concatenated with a separator. For example, I need ValueCode to contain 'code1; code2' and Value to contain 'value 1; value2'. How can I achieve that?

                  推荐答案

                  如果你想要连接字符串,你可以使用 xuery:

                  you can use xuery if you want concatenated strings:

                  SELECT 
                      Tbl.Col.query('for $i in value return concat($i/text()[1], ";")').value('.', 'nvarchar(max)'),
                      Tbl.Col.query('for $i in value return concat($i/@code, ";")').value('.', 'nvarchar(max)')
                  FROM @xml.nodes('root/element/subelement') Tbl(Col);
                  

                  如果您希望将值放入行中:

                  if you want your values into rows:

                  SELECT 
                      Tbl.Col.value('.', 'nvarchar(max)'),
                      Tbl.Col.value('@code', 'nvarchar(max)')
                  FROM @xml.nodes('root/element/subelement/value') Tbl(Col);
                  

                  sql 小提琴演示

                  这篇关于在 T-SQL 中通过 XQuery 选择时连接 xml 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:SQL Server 生成带有通用字段元素的 XML 下一篇:获取嵌套的 XML 输出 sql server

                  相关文章

                  最新文章

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

                      <tfoot id='Nfgt4'></tfoot>
                      <legend id='Nfgt4'><style id='Nfgt4'><dir id='Nfgt4'><q id='Nfgt4'></q></dir></style></legend>
                    1. <small id='Nfgt4'></small><noframes id='Nfgt4'>

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