<tfoot id='Uk7J8'></tfoot>
    • <bdo id='Uk7J8'></bdo><ul id='Uk7J8'></ul>

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

  • <legend id='Uk7J8'><style id='Uk7J8'><dir id='Uk7J8'><q id='Uk7J8'></q></dir></style></legend>

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

        XQuery 存在检查选择 sql 查询

        时间:2023-06-07

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

                  <bdo id='nUqZW'></bdo><ul id='nUqZW'></ul>
                • <small id='nUqZW'></small><noframes id='nUqZW'>

                    <tbody id='nUqZW'></tbody>
                  本文介绍了XQuery 存在检查选择 sql 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个带有 xml 列的 sql 表,其中包含如下 xml 的值

                  I have one sql table with xml column which holds the value like below xml

                  <Security xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                    <Dacl>
                      <ACEInformation>
                        <UserName>Authenticated Users</UserName>
                        <Access>Allow</Access>
                        <IsInherited>false</IsInherited>
                        <ApplyTo>This object only</ApplyTo>
                        <Permission>List Contents</Permission>
                        <Permission>Read All Properties</Permission>
                        <Permission>Read Permissions</Permission>
                      </ACEInformation>
                      <ACEInformation>
                        <UserName>Administrator</UserName>
                        <Access>Allow</Access>
                        <IsInherited>false</IsInherited>
                        <ApplyTo>This object only</ApplyTo>
                        <Permission>Read All Properties</Permission>
                        <Permission>Delete</Permission>
                      </ACEInformation>
                      <ACEInformation>
                        <UserName>Admin2</UserName>
                        <Access>Allow</Access>
                        <IsInherited>false</IsInherited>
                        <ApplyTo>This object only</ApplyTo>
                        <Permission>Read All Properties</Permission>
                        <Permission>Delete</Permission>
                      </ACEInformation>
                      <ACEInformation>
                        <UserName>Admin2</UserName>
                        <Access>Deny</Access>
                        <IsInherited>false</IsInherited>
                        <ApplyTo>This object only</ApplyTo>
                        <Permission>Read All Properties</Permission>
                        <Permission>Delete</Permission>
                      </ACEInformation>
                    </Dacl>
                  </Security>
                  

                  这里我的需要是,我必须查询具有访问:允许权限:删除值的所有用户名值.为此,我正在使用以下 XQuery.

                  Here my need is, I have to query all UserName values who are having values Access: Allow and Permission: Delete. For that, I am using following XQuery.

                  select (
                         select A.X.value('(UserName/text())[1]', 'nvarchar(max)')+';'
                         from T.xmlColumn.nodes('/Security/Dacl/ACEInformation[Access = "Allow" and Permission = "Delete"]') as A(X)
                         for xml path(''), type
                         ).value('text()[1]', 'nvarchar(max)')
                  from myTable as T
                  

                  它返回值:Administrator;Admin2 用于上述 xml.查询工作正常..

                  It returns the value : Administrator;Admin2 for above xml. the query is working fine..

                  但在这里,我希望结果只有一个条目 Administrator 而不是 Admin2..因为 Admin2 在两个不同的 ACEInformation 节点中同时具有 Access:AllowAccess: Deny 值..

                  But here, I expect the result only one entry Administrator not Admin2.. because Admin2 has both Access:Allow and Access: Deny values in two different ACEInformation node..

                  在这种情况下,我必须从结果中排除 Admin2,即使它具有 Access:Allow.

                  In that case, I have to exclude Admin2 from result, even though it has the Access:Allow.

                  谁能给我这个案例的xquery?

                  Can you any one give me the xquery for this case?

                  推荐答案

                  with cte as (
                      select
                          A.X.value('(UserName/text())[1]', 'nvarchar(max)') as UserName,
                          A.X.value('(Access/text())[1]', 'nvarchar(max)') as Access
                      from myTable as T
                          outer apply T.xmlColumn.nodes('/Security/Dacl/ACEInformation[Permission = "Delete"]') as A(X)
                  )
                  select *
                  from cte as c1
                  where
                      c1.Access = 'Allow' and
                      not exists (select * from cte as c2 where c2.UserName = c1.UserName and c2.Access = 'Deny')
                  

                  sql 小提琴演示

                  这个会给你想要的结果.

                  This one will give you desired result.

                  with cte as (
                      select
                          T.ID,
                          A.X.value('(UserName/text())[1]', 'nvarchar(max)') as UserName,
                          A.X.value('(Access/text())[1]', 'nvarchar(max)') as Access
                      from myTable as T
                          outer apply T.xmlColumn.nodes('/Security/Dacl/ACEInformation[Permission = "Delete"]') as A(X)
                  )
                  select
                      T.ID,
                      stuff(
                          (
                              select ',' + c1.UserName
                              from cte as c1
                              where
                                c1.ID = T.ID and c1.Access = 'Allow' and
                                not exists (select * from cte as c2 where c2.ID = T.ID and c2.UserName = c1.UserName and c2.Access = 'Deny')
                              for xml path(''), type
                          ).value('.', 'nvarchar(max)')
                      ,1,1,'')
                  from myTable as T
                  

                  sql 小提琴演示

                  我认为使用纯 XQuery 可以做到这一点,稍后尝试添加.

                  I think it's possible to do this with pure XQuery, try to add this later.

                  这篇关于XQuery 存在检查选择 sql 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                        <tbody id='6jwAE'></tbody>

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

                            <small id='6jwAE'></small><noframes id='6jwAE'>

                            <tfoot id='6jwAE'></tfoot>

                            <legend id='6jwAE'><style id='6jwAE'><dir id='6jwAE'><q id='6jwAE'></q></dir></style></legend>