C# sqlserver2005中的XML查询

C# sqlserver2005中的XML查询,c#,mysql,sql,sql-server,xml,C#,Mysql,Sql,Sql Server,Xml,我正在运行的查询运行不正常,以下是我的代码: 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="

我正在运行的查询运行不正常,以下是我的代码:

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),并查看可见性是否为真

此时,我的代码返回所有正确的列,但列“first”、“second”和“third”的值都返回0。但是他们中的一些应该返回1

我不明白为什么他们都返回0

我在这里上传了XML:txt.do/dev1您将看到colFirstChoiceVendorPaymentTerms和colSecondChoiceVendorPaymentTerms的可见性设置为true。但Colthird ChoiceVendorPaymentTerms不可见。这就是我要检查的。是否存在可见性和列

再次感谢你的帮助

'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')