2011-05-25 82 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

相關問題