2011-05-25 80 views
1

我想找到一个空的组织元素,它不是parentProblem元素的直接子元素。查找孩子,其中父母不是某个元素

像这样..

select * from Audit.PatientAudit pa 
where pa.BeforeXml.exist('//*:organisation[not(../*:parentProblem)]') = 1 

但它似乎没有工作,任何想法?

回答

2
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 
+0

+1 @Mikael Eriksson - 干杯,但我说我的问题有点不对。所有organisation元素都是空的,但我想找到没有属性的元素!我知道它们是什么属性(只有两个),所以我可以明确地用'not(@guid)'检查是否存在abscense,但为了完整性,有没有更好的方法? – 2011-05-26 09:05:35

+0

@Dog Ears - 更新回答。我是否正确理解你,只有0属性的行? – 2011-05-26 10:26:18

相关问题