Sql server 2008 查找父元素不是特定元素的子元素

Sql server 2008 查找父元素不是特定元素的子元素,sql-server-2008,xquery,xquery-sql,Sql Server 2008,Xquery,Xquery Sql,我想找到一个空的组织元素,它不是parentProblem元素的直接子元素 就这样 select * from Audit.PatientAudit pa where pa.BeforeXml.exist('//*:organisation[not(../*:parentProblem)]') = 1 但它似乎不起作用,有什么想法吗?declare@t table(BeforeXml) declare @T table(BeforeXml xml) insert into @T values

我想找到一个空的组织元素,它不是parentProblem元素的直接子元素

就这样

select * from Audit.PatientAudit pa
where pa.BeforeXml.exist('//*:organisation[not(../*:parentProblem)]') = 1
但它似乎不起作用,有什么想法吗?

declare@t table(BeforeXml)
declare @T table(BeforeXml xml)

insert into @T values
('<root>
    <parentProblem>
      <organisation/>
    </parentProblem>
  </root>'), 
('<root>
    <anotherProblem>
      <organisation/>
    </anotherProblem>
  </root>'),
('<root>
    <anotherProblem>
      <organisation ID="1"/>
    </anotherProblem>
  </root>') 

select *
from @T pa
where pa.BeforeXml.exist('//organisation[local-name(..)!="parentProblem" and count(@*)=0]') = 1
插入到@T值中 (' '), (' '), (' ') 挑选* 来自@T pa 其中pa.BeforeXml.exist('//organization[本地名称(..)!=“parentProblem”和count(@*)=0]')=1
+1@Mikael Eriksson-干杯,但我的问题措辞稍有错误。所有Organization元素都是空的,但我想找到没有属性的元素!我知道它们的属性是什么(只有两个),因此我可以使用
not(@guid)
明确检查是否存在absscense,例如,为了完整性,是否有更好的方法?@Dog Ears-更新的答案。我是否正确理解了您的意思,只有属性为0的行?