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

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

    1. 获取嵌套的 XML 输出 sql server

      时间:2023-06-07
    2. <legend id='fn5Vd'><style id='fn5Vd'><dir id='fn5Vd'><q id='fn5Vd'></q></dir></style></legend>
      • <bdo id='fn5Vd'></bdo><ul id='fn5Vd'></ul>
        <tfoot id='fn5Vd'></tfoot>

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

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

                本文介绍了获取嵌套的 XML 输出 sql server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我的 sql server 数据库的 xml 输出有问题.我的桌子:

                I have a problem with my xml output from sql server database. My table:

                CREATE TABLE [dbo].[test_table](
                    [id] [int] IDENTITY(1,1) NOT NULL,
                    [firstname] [nvarchar](255) NULL,
                    [lastname] [nvarchar](255) NULL,
                    [city] [nvarchar](255) NULL,
                    [street] [nvarchar](255) NULL,
                    [streetno] [int] NULL
                )
                

                我想要输出,其中 Address 嵌套在每个 Person 中,如下所示:

                I want the output, where Address is nested inside each Person, like this:

                <Root>
                  <Person id="1">
                    <firstname>Stefanie</firstname>
                    <lastname>Buckley</lastname>
                    <Address>
                      <city>Oklahoma</city>
                      <street> Cowley Road</street>
                      <streetno>34</streetno>
                    </Address>
                  </Person>
                  <Person id="2">
                    <firstname>Sandy</firstname>
                    <lastname>Mc Gee</lastname>
                    <Address>
                      <city>Montgomery</city>
                      <street> Hague Parkway</street>
                      <streetno>27</streetno>
                    </Address>
                  </Person>
                </Root>
                

                我尝试过嵌套选择,例如:

                I've tried with nested select like:

                 select tbl1.id '@id', tbl1.firstname, tbl1.lastname,
                 (
                 select city,street,streetno from test_table as tbl2
                 where tbl2.id = tbl1.id
                 for xml path('Address')
                 ) 
                 from test_table as tbl1
                 for xml path('Person'), Root('Root')
                

                但输出如下:

                <Root>
                  <Person id="1">
                    <firstname>Stefanie</firstname>
                    <lastname>Buckley</lastname>&lt;Address&gt;&lt;city&gt;Oklahoma&lt;/city&gt;&lt;street&gt; Cowley Road&lt;/street&gt;&lt;streetno&gt;34&lt;/streetno&gt;&lt;/Address&gt;</Person>
                  <Person id="2">
                    <firstname>Sandy</firstname>
                    <lastname>Mc Gee</lastname>&lt;Address&gt;&lt;city&gt;Anchorage&lt;/city&gt;&lt;street&gt; North Green Clarendon Road&lt;/street&gt;&lt;streetno&gt;29&lt;/streetno&gt;&lt;/Address&gt;</Person>
                  <Person id="3">
                

                我做错了什么?

                推荐答案

                你忘记了 ,输入,你不需要 wxtra 从表中读取.

                You forgot , type and you don't need wxtra reading from table.

                select tbl1.id '@id'
                    , tbl1.firstname
                    , tbl1.lastname
                    , (
                        select city
                            , street
                            , streetno
                        for xml path('Address'), type
                    ) 
                from test_table as tbl1
                for xml path('Person'), type, Root('Root')
                

                这篇关于获取嵌套的 XML 输出 sql server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 T-SQL 中通过 XQuery 选择时连接 xml 值 下一篇:SQL 根据兄弟节点属性值选择 XML 节点

                相关文章

                最新文章

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

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

                    <tfoot id='UGjnZ'></tfoot>