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

  • <small id='69mPn'></small><noframes id='69mPn'>

    <legend id='69mPn'><style id='69mPn'><dir id='69mPn'><q id='69mPn'></q></dir></style></legend>
      <bdo id='69mPn'></bdo><ul id='69mPn'></ul>

        <tfoot id='69mPn'></tfoot>
      1. sql server 上的 XML 解析

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

          1. <tfoot id='dpK4E'></tfoot>

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

                <tbody id='dpK4E'></tbody>

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

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

                  问题描述

                  限时送ChatGPT账号..

                  如何以格式返回数据:

                  Column Name t01     t02     t03     t04
                  Data        c01     c02     c03     c04
                  
                  <orders xmlns="www address">
                      <order>
                          <order-date>2019-09-05</order-date>
                          <created-by>storefront</created-by>
                          <original-order-no>000001</original-order-no>
                          <currency>USD</currency>
                          <taxation>gross</taxation>
                          <invoice-no>0099999</invoice-no>
                          <custom-attributes>
                              <custom-attribute attribute-id="t01">c01</custom-attribute>
                              <custom-attribute attribute-id="t02">c02</custom-attribute>
                              <custom-attribute attribute-id="t03">c03</custom-attribute>
                              <custom-attribute attribute-id="t04">c04</custom-attribute>
                          </custom-attributes>    
                      </order>
                  </orders>
                  

                  推荐答案

                  从你的问题来看,有一点不清楚:输出列的命名.

                  From your question there's one thing not clear: The naming of the output columns.

                  在您预期的输出中,它们的名称与它们的 attribute-id 一样.但在您的评论中,听起来像是您选择了前 4 个属性,而您想忽略其余属性.

                  In your expected output they are named like their attribute-id. But in your comments it sounds, like you are picking the first 4 attributes and you want to omit the rest.

                  我想展示两种方法,选择你更喜欢的一种:

                  I want to show two approaches, pick the one you like more:

                  DECLARE @mockupTable TABLE(ID INT IDENTITY, YourXml XML);
                  INSERT INTO @mockupTable VALUES
                  (N'<orders xmlns="www address">
                      <order>
                          <order-date>2019-09-05</order-date>
                          <created-by>storefront</created-by>
                          <original-order-no>000001</original-order-no>
                          <currency>USD</currency>
                          <taxation>gross</taxation>
                          <invoice-no>0099999</invoice-no>
                          <custom-attributes>
                              <custom-attribute attribute-id="t01">c01</custom-attribute>
                              <custom-attribute attribute-id="t02">c02</custom-attribute>
                              <custom-attribute attribute-id="t03">c03</custom-attribute>
                              <custom-attribute attribute-id="t04">c04</custom-attribute>
                          </custom-attributes>    
                      </order>
                  </orders>');
                  

                  --此查询将使用 attribute-id 选择相应的属性.
                  --我们可以使用相同的名称安全地返回它
                  --如果你的XML没有对应的属性,就会出现NULL值

                  --This query will use the attribute-id to pick the corresponding attribute.
                  --We can savely return this with the same name
                  --If your XML does not have the corresponding attribute, there will be a NULL value

                  WITH XMLNAMESPACES(DEFAULT 'www address')
                  SELECT o.value('(order-date/text())[1]','date') OrderDate
                        --As in your other questions
                        ,o.value('(custom-attributes/custom-attribute[@attribute-id="t01"]/text())[1]','varchar(100)') AS t01 
                        ,o.value('(custom-attributes/custom-attribute[@attribute-id="t02"]/text())[1]','varchar(100)') AS t02
                        ,o.value('(custom-attributes/custom-attribute[@attribute-id="t03"]/text())[1]','varchar(100)') AS t03 
                        ,o.value('(custom-attributes/custom-attribute[@attribute-id="t04"]/text())[1]','varchar(100)') AS t04 
                  FROM @mockupTable t
                  CROSS APPLY t.YourXml.nodes('/orders/order') A(o);
                  

                  --这个比较容易.它只会选择前四个属性,无论它们有什么 id.

                  --This one is easier. It will pick just the first four attributes, no matter what id they have.

                  WITH XMLNAMESPACES(DEFAULT 'www address')
                  SELECT o.value('(order-date/text())[1]','date') OrderDate
                        --As in your other questions
                        ,o.value('(custom-attributes/custom-attribute[1]/text())[1]','varchar(100)') AS ca1 
                        ,o.value('(custom-attributes/custom-attribute[2]/text())[1]','varchar(100)') AS ca2
                        ,o.value('(custom-attributes/custom-attribute[3]/text())[1]','varchar(100)') AS ca3 
                        ,o.value('(custom-attributes/custom-attribute[4]/text())[1]','varchar(100)') AS ca4 
                  FROM @mockupTable t
                  CROSS APPLY t.YourXml.nodes('/orders/order') A(o);
                  

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

                  上一篇:预期 XML 解析分号 - 仅在替换 &amp; 时与 & 下一篇:Oracle XMLTable-从父节点获取列

                  相关文章

                  最新文章

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

                      <tfoot id='AMGCa'></tfoot><legend id='AMGCa'><style id='AMGCa'><dir id='AMGCa'><q id='AMGCa'></q></dir></style></legend>

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