簡體   English   中英

SQL Server 2005中的XML查詢

[英]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?

  1. 您正在尋找屬性根節點。
  2. 您正在將屬性@name與節點值進行比較
  3. 當您開始尋找名稱為Visible的屬性時,您的屬性級別太高了。

您應該看起來像這樣。

'//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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM