问题描述
|
我想找到一个空的组织元素,它不是parentProblem元素的直接子元素。
像这样
select * from Audit.PatientAudit pa
where pa.BeforeXml.exist(\'//*:organisation[not(../*:parentProblem)]\') = 1
但这似乎行不通,有什么主意吗?
解决方法
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