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

      1. <small id='8zSHa'></small><noframes id='8zSHa'>

          <bdo id='8zSHa'></bdo><ul id='8zSHa'></ul>
      2. SQL Server“FOR XML"连接两个表的查询的输出

        时间:2023-06-06

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

                  <tbody id='unY2X'></tbody>
              • <legend id='unY2X'><style id='unY2X'><dir id='unY2X'><q id='unY2X'></q></dir></style></legend>
                <tfoot id='unY2X'></tfoot>

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

                • 本文介绍了SQL Server“FOR XML"连接两个表的查询的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我不熟悉 SQL Server 中的FOR XML"功能.我使用的是 SQL Server 2012.

                  I'm new to the "FOR XML" feature in SQL Server. I am using SQL Server 2012.

                  我有两个表格,Word 和 Word_Expansion.

                  I have two tables, Word and Word_Expansion.

                  示例数据:

                  表[字]:

                  WordOID   Word
                  -------   ----    
                        1   PIPE
                        2   WIRE
                  

                  表 [Word_Expansion]:

                  table [Word_Expansion]:

                  WEOID  fk_WordOID  Word_Expansion
                  -----  ----------  --------------
                      1          2             COAX
                      2          2    SPEAKER CABLE
                      3          1          CONDUIT
                  

                  现在,我想生成类似于以下内容的 XML:

                  Now, I would like to produce XML something like:

                  <expansion>
                    <sub>WIRE</sub>
                    <sub>SPEAKER CABLE</sub>
                  </expansion>
                  <expansion>
                    <sub>PIPE</sub>
                    <sub>CONDUIT</sub>
                  </expansion>
                  

                  我在制作 XML FOR 语句方面进行了各种努力,但我似乎无法理解我需要做什么才能将这两个表混合成正确的 XML 输出.我将进一步深入研究 XML FOR 语法,但如果您有时间了解这一点...

                  I have come close with various efforts at crafting XML FOR statements, but I just can't seem to grasp what it is that I need to do to get these two tables mashed into the right XML output. I'll be digging further into XML FOR syntax, but if you have a moment and know this well...

                  有人对我应该尝试什么有任何指示吗?

                  Does anyone have any pointers as to what I should try?

                  推荐答案

                  这应该对你有用:

                  SQL:

                  SELECT Word Sub,      
                          (      
                               SELECT Word_Expansion  AS Sub   
                               FROM Word_Expansion WE
                               WHERE WE.fk_WordOID = W.WordOID 
                               FOR XML PATH(''), type 
                          )      
                  FROM Word W
                  FOR XML PATH ('Expansion')   
                  

                  XML 输出:

                  <Expansion>
                    <Sub>Pipe</Sub>
                    <Sub>CONDUIT</Sub>
                  </Expansion>
                  <Expansion>
                    <Sub>Wire</Sub>
                    <Sub>COAX</Sub>
                    <Sub>SPEAKER CABLE</Sub>
                  </Expansion>
                  

                  虽然我不确定您为什么要将 Word.Word 归类为Sub"?这不应该是 Word_Expansion 的父级(应该是 sub?)

                  Although i'm not sure why you want Word.Word to be classified as "Sub"? Shouldn't this instead be the parent of Word_Expansion (which should be sub?)

                  我发现这个链接在查看 FOR XML 和嵌套查询时非常有用 嵌套 FOR XML

                  I found this link quite useful when looking into FOR XML and nested queries Nested FOR XML

                  这篇关于SQL Server“FOR XML"连接两个表的查询的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否有从 XML 模式生成数据库模式的工具? 下一篇:ValidateRequest 错误或 SQL Server 错误?

                  相关文章

                  最新文章

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

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

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