1. <small id='KMYIQ'></small><noframes id='KMYIQ'>

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

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

    1. 匹配嵌套 XML 节点内容的 SQL

      时间:2023-06-07

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

          <tbody id='xe8w0'></tbody>
          <bdo id='xe8w0'></bdo><ul id='xe8w0'></ul>

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

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

              1. 本文介绍了匹配嵌套 XML 节点内容的 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个包含 XML 嵌套的数据库字段,如下所示:

                <预><代码><配置><模块><genericMailer><模块内容><数据><sendMethod>电子邮件</sendMethod>

                我的 XML 可以包含 元素(及其子节点)的许多实例.我想找到所有 实例的所有行,其中 包含Mail".

                我可以像这样获取 sendMethod 的所有值:

                SELECT a.ApplicationId,x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod来自应用程序 a交叉应用 a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol);

                但是我不知道如何只搜索匹配的值.我需要什么 WHERE 子句?

                解决方案

                这里有一些可能的方法:

                一个.使用 value() 方法提取 sendMethod 值,然后检查 WHERE 子句中的值是否为 LIKE '%mail%' :

                SELECT a.ApplicationId,x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod来自应用程序 a交叉应用 a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol)WHERE x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') LIKE '%mail%'

                B.使用 XPath 方法 contains() 检查 sendMethod 值是否包含子字符串 "mail" 和 SQL Server 方法 exist() 过滤通过检查的行:

                SELECT a.ApplicationId,x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod来自应用程序 a交叉应用 a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol)WHERE x.XmlCol.exist('moduleContent/data/sendMethod[contains(.,"mail")]') = 1

                I have a database field containing XML nested like this:

                <configuration>
                   <modules>
                    <genericMailer>
                      <moduleContent>
                        <data>
                          <sendMethod>Email</sendMethod>
                

                My XML can contain many instances of the <genericMailer> element (and it's subnodes). I want to find all rows where there are any instances of <genericMailer> where the <sendMethod> contains 'Mail'.

                I can get all of the values for sendMethod like this:

                SELECT  a.ApplicationId,
                        x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod
                FROM    Applications a
                CROSS APPLY a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol);
                

                however I don't know how to search only for matching values. What's the WHERE clause I need?

                解决方案

                Here are some possible ways :

                a. Using value() method to extract sendMethod value then check if the value LIKE '%mail%' in WHERE clause :

                SELECT  a.ApplicationId,
                        x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod
                FROM    Applications a
                CROSS APPLY a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol)
                WHERE  x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') LIKE '%mail%'
                

                b. Using XPath method contains() to check if sendMethod value contains substring "mail" and SQL Server method exist() to filter rows that pass the check :

                SELECT  a.ApplicationId,
                        x.XmlCol.value('(moduleContent/data/sendMethod)[1]','VARCHAR(100)') AS SendMethod
                FROM    Applications a
                CROSS APPLY a.AppConfig.nodes('/configuration/modules/genericMailer') x(XmlCol)
                WHERE x.XmlCol.exist('moduleContent/data/sendMethod[contains(.,"mail")]') = 1
                

                这篇关于匹配嵌套 XML 节点内容的 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将数据从 xml 保存到 sql 2008? 下一篇:如何在 SQL Server 2008 中读取 XML 列?

                相关文章

                最新文章

                    <bdo id='Ndghb'></bdo><ul id='Ndghb'></ul>

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

                  1. <legend id='Ndghb'><style id='Ndghb'><dir id='Ndghb'><q id='Ndghb'></q></dir></style></legend>

                    <tfoot id='Ndghb'></tfoot>

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