简体   繁体   English

SQL Server 2005中的XML查询

[英]XML query in SQL Server 2005

a query i am running is not functioning properly, here is my code: 我正在运行的查询无法正常运行,这是我的代码:

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'

I have a lengthy piece of XML and i want to check if certain properties such as(colThirdChoiceVendorPaymentTerms) are present in the XML AND to see if the visibility is true. 我有一段很长的XML,我想检查XML中是否存在某些属性,例如(colThirdChoiceVendorPaymentTerms),并查看可见性是否为true。

At the minute my code returns all the correct columns but the values for columns 'first', 'second' and 'third' all return 0. But some of them should be returning 1... 一分钟,我的代码返回了所有正确的列,但是列“ first”,“ second”和“ third”的值都返回0。但是其中一些应该返回1 ...

I dont understand why all of they all return 0? 我不明白为什么他们都返回0?

I have uploaded the XML here: txt.do/dev1 you will see that the visibility for colFirstChoiceVendorPaymentTerms and colSecondChoiceVendorPaymentTerms is set to true. 我已将XML上传到此处:txt.do/dev1,您将看到colFirstChoiceVendorPaymentTerms和colSecondChoiceVendorPaymentTerms的可见性设置为true。 but there is no visibility for colThirdChoiceVendorPaymentTerms. 但是colThirdChoiceVendorPaymentTerms没有可见性。 this is what i want to check. 这是我要检查的。 if visibility and column are there or not. 是否存在可见性和列。

Thank you again for your help. 再次感谢你的帮助。

'property[@name="colSecondChoiceVendorPaymentTerms"]//property[@name=''Visible'' and text()=''true'']'

I dont understand why all of they all return 0? 我不明白为什么他们都返回0?

  1. You are looking for a property root node. 您正在寻找属性根节点。
  2. You are comparing the attribute @name where you should compare against a node value 您正在将属性@name与节点值进行比较
  3. You are one property level too deep when you start to look for the property with name Visible. 当您开始寻找名称为Visible的属性时,您的属性级别太高了。

Your should look like this. 您应该看起来像这样。

'//property[.="colSecondChoiceVendorPaymentTerms"]/../property[@name=''Visible'' and text()=''true'']'

Or you could not use deep search and use value to get the value of the node @name="Visible" . 否则,您将无法使用深度搜索并使用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