繁体   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