<small id='1t00L'></small><noframes id='1t00L'>

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

      FOR XML 通过树概念中的属性进行多重控制

      时间:2023-06-05
    3. <tfoot id='JwST9'></tfoot>
          <bdo id='JwST9'></bdo><ul id='JwST9'></ul>

              <tbody id='JwST9'></tbody>

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

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

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

              1. 本文介绍了FOR XML 通过树概念中的属性进行多重控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我想弄清楚一个问题.

                我已经对简单的订购问题有疑问,但我想订购更多详细信息.在此链接下方检查:SQL Server : FOR XML 按属性排序控制

                I already had question about simple ordering issue but I want to order more detail. check below this link : SQL Server : FOR XML sorting control by attribute

                我做了一个例子.

                SQL 查询.

                select (
                    select '123' AS '@id', ( 
                        select 
                        (
                            select 'test' AS '@testid' , '20' AS '@order'
                            FOR XML path ('tree') , TYPE
                        ),
                        (
                            select 'test2' AS '@testid' , '30' AS '@order'
                            FOR XML path ('tree-order') , TYPE
                        ),
                        (
                            select 'test' AS '@testid' , '10' AS '@order'
                            FOR XML path ('tree') , TYPE
                        )
                        FOR XML path ('Node') , TYPE
                    )
                    FOR XML path ('Sample') , TYPE
                    ),
                    (select '456' AS '@id', ( 
                        select 
                        (
                            select 'test' AS '@testid' , '20' AS '@order'
                            FOR XML path ('tree') , TYPE
                        ),
                        (
                            select 'test2' AS '@testid' , '30' AS '@order'
                            FOR XML path ('tree-order') , TYPE
                        ),
                        (
                            select 'test' AS '@testid' , '10' AS '@order'
                            FOR XML path ('tree') , TYPE
                        )
                        FOR XML path ('Node') , TYPE
                    )
                    FOR XML path ('Sample') , TYPE)
                FOR XML path ('Main') , TYPE
                

                结果:

                <Main>
                  <Sample id="123">
                    <Node>
                      <tree testid="test" order="20" />
                      <tree-order testid="test2" order="30" />
                      <tree testid="test" order="10" />
                    </Node>
                  </Sample>
                  <Sample id="456">
                    <Node>
                      <tree testid="test" order="20" />
                      <tree-order testid="test2" order="30" />
                      <tree testid="test" order="10" />
                    </Node>
                  </Sample>
                </Main>
                

                预期结果:

                <Main>
                  <Sample id="123">
                    <Node>
                      <tree testid="test" order="10" />
                      <tree testid="test" order="20" />
                      <tree-order testid="test2" order="30" />
                    </Node>
                  </Sample>
                  <Sample id="456">
                    <Node>
                      <tree testid="test" order="10" />
                      <tree testid="test" order="20" />
                      <tree-order testid="test2" order="30" />
                    </Node>
                  </Sample>
                </Main>
                

                最终结果:

                <Main>
                  <Sample id="123">
                    <Node>
                      <tree testid="test" />
                      <tree testid="test" />
                      <tree-order testid="test2" />
                    </Node>
                  </Sample>
                  <Sample id="456">
                    <Node>
                      <tree testid="test" />
                      <tree testid="test" />
                      <tree-order testid="test2" />
                    </Node>
                  </Sample>
                </Main>
                

                这是按树序排列的.

                最后我不想在属性中显示订单信息

                finally I don't want to show order information in attribute

                有人有好主意吗?

                感谢所有对此感兴趣的人.

                Thank you for everybody who interesting to this.

                更新----------------------------------------

                Updated ----------------------------------------

                谢谢大家,最后我解决了以下关于 order by 和 remove 属性问题的问题:

                Thank you every body finally I solved problem as below about order by and remove attribute issue :

                declare @resultData xml = (select @data.query('
                  element Main {
                    for $s in Main/Sample
                    return element Sample {
                      $s/@*,
                      for $n in $s/Node
                      return element Node {
                        for $i in $n/* 
                        order by $i/@order
                        return $i 
                      }
                    }  
                  }'));
                
                  SET @resultData.modify('delete (Main/Sample/Node/tree/@order)');
                  SET @resultData.modify('delete (Main/Sample/Node/tree-order/@order)');
                
                  select @resultData
                

                推荐答案

                select @data.query('
                  element Main {
                    for $s in Main/Sample
                    return element Sample {
                      $s/@*,
                      for $n in $s/Node
                      return element Node {
                        for $i in Node/* 
                        order by $i/@order
                        return 
                          if ($i/self::tree)
                          then element tree { $i/@testid }
                          else element tree-order { $i/@testid }
                        }
                      }
                    }  
                  }')
                

                这篇关于FOR XML 通过树概念中的属性进行多重控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 xquery 转换为 html? 下一篇:使用 Xquery 透视复杂的 XML

                相关文章

                最新文章

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

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

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