[英]XML query in SQL Server 2005
我正在運行的查詢無法正常運行,這是我的代碼:
select a.id, a.userid, c.firstname + ' ' + c.lastname AS Name, a.objectid, a.settings,
CAST(settings as XML).exist('property[@name=''colFirstChoiceVendorPaymentTerms'']') as first,
CAST(settings as XML).exist('property[@name="colSecondChoiceVendorPaymentTerms"]//property[@name=''Visible'' and text()=''true'']') as second,
CAST(settings as XML).exist('property[@name="colThirdChoiceVendorPaymentTerms"]//property[@name=''Visible'' and text()=''true'']') as third
FROM wcukopera05.vstx.dbo.screenlayout a
join wcuksql01.hrsystem.dbo.person c
on a.UserId=c.Id
where a.objectid = 'gridViewCustomerCurrentRatesCosts'
我有一段很長的XML,我想檢查XML中是否存在某些屬性,例如(colThirdChoiceVendorPaymentTerms),並查看可見性是否為true。
一分鍾,我的代碼返回了所有正確的列,但是列“ first”,“ second”和“ third”的值都返回0。但是其中一些應該返回1 ...
我不明白為什么他們都返回0?
我已將XML上傳到此處:txt.do/dev1,您將看到colFirstChoiceVendorPaymentTerms和colSecondChoiceVendorPaymentTerms的可見性設置為true。 但是colThirdChoiceVendorPaymentTerms沒有可見性。 這是我要檢查的。 是否存在可見性和列。
再次感謝你的幫助。
'property[@name="colSecondChoiceVendorPaymentTerms"]//property[@name=''Visible'' and text()=''true'']'
我不明白為什么他們都返回0?
@name
與節點值進行比較 您應該看起來像這樣。
'//property[.="colSecondChoiceVendorPaymentTerms"]/../property[@name=''Visible'' and text()=''true'']'
否則,您將無法使用深度搜索並使用value獲取節點@name="Visible"
。
settings.value('(/XtraSerializer/property/property[property/@name="Name" and property = "colSecondChoiceVendorPaymentTerms"]/property[@name = "Visible"])[1]', 'bit')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.