1. <legend id='z71kP'><style id='z71kP'><dir id='z71kP'><q id='z71kP'></q></dir></style></legend>
        <bdo id='z71kP'></bdo><ul id='z71kP'></ul>

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

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

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

        从 Sql Server 中的 xml 中的最后一个获取第 n 个元素

        时间:2023-06-07

          • <tfoot id='GU3g0'></tfoot>
              <tbody id='GU3g0'></tbody>
              <bdo id='GU3g0'></bdo><ul id='GU3g0'></ul>

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

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

                  本文介绍了从 Sql Server 中的 xml 中的最后一个获取第 n 个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  请考虑这个 XML:

                  <Employees>
                      <Person>
                          <ID>1000</ID>
                          <Name>Nima</Name>
                          <LName>Agha</LName>
                      </Person>
                      <Person>
                          <ID>1001</ID>
                          <Name>Ligha</Name>
                          <LName>Ligha</LName>
                      </Person>
                      <Person>
                          <ID>1002</ID>
                          <Name>Jigha</Name>
                          <LName>Jigha</LName>
                      </Person>
                      <Person>
                          <ID>1003</ID>
                          <Name>Aba</Name>
                          <LName>Aba</LName>
                      </Person>
                  </Employees>
                  

                  我想写一个函数来获取一个数字,然后我得到第n个Person元素和Name.例如,如果 0 传递给我的函数,我返回 Aba,如果 1 传递给我的函数,我返回 Jigha.

                  I want to write a function that gets a number, and then I get nth Person element, and Name. For example if 0 pass to my function I return Aba, if 1 pass to my function I return Jigha.

                  推荐答案

                  这应该有效.将 @index 变量的值设置为要查找的记录的编号,相对于列表的末尾:

                  This should work. Set the value of the @index variable as the number of the record to find, relative to the end of the list:

                  declare @index int = 1
                  declare @xml xml = '<Employees>
                      <Person>
                          <ID>1000</ID>
                          <Name>Nima</Name>
                          <LName>Agha</LName>
                      </Person>
                      <Person>
                          <ID>1001</ID>
                          <Name>Ligha</Name>
                          <LName>Ligha</LName>
                      </Person>
                      <Person>
                          <ID>1002</ID>
                          <Name>Jigha</Name>
                          <LName>Jigha</LName>
                      </Person>
                      <Person>
                          <ID>1003</ID>
                          <Name>Aba</Name>
                          <LName>Aba</LName>
                      </Person>
                  </Employees>'
                  
                  select t2.person.value('(Name/text())[1]','varchar(50)')
                  from @xml.nodes('Employees/Person[position()=(last()-sql:variable("@index"))]') as t2(person)
                  

                  这篇关于从 Sql Server 中的 xml 中的最后一个获取第 n 个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:SQL 根据兄弟节点属性值选择 XML 节点 下一篇:用xml到sql按条件更新所有节点

                  相关文章

                  最新文章

                    <legend id='fvYwd'><style id='fvYwd'><dir id='fvYwd'><q id='fvYwd'></q></dir></style></legend>

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

                    2. <tfoot id='fvYwd'></tfoot>
                        <bdo id='fvYwd'></bdo><ul id='fvYwd'></ul>

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