对您的问题的回答很大程度上取决于您使用的 xml 架构。例如,如果您使用这样的属性 xml:
'<Item ID="1" Visibility="1" />'
您可以使用此查询过滤项目:
select *
from temp
where data.exist('Item[@Visibility = "1"]') = 1
看到这个sql fiddle demo
在我们没有您的 xml 的确切架构之前,很难更准确地回答。
更新
所以看起来你有 DevExpress 设置 xml 存储在你的数据库中。因此,如果您的简化 xml 是这样的:
<XtraSerializer version="1.0" application="View">
<property name="Columns" iskey="true" value="9">
<property name="colFirstChoiceVendorPaymentTerms" isnull="true" iskey="true">
<property name="Visible">true</property>
</property>
<property name="colSecondChoiceVendorPaymentTerms" isnull="true" iskey="true">
<property name="Visible">false</property>
</property>
</property>
</XtraSerializer>
然后你可以像这样查询它:
select
data.value('(XtraSerializer/property/property[@name="colFirstChoiceVendorPaymentTerms"]/property[@name="Visible"])[1]', 'bit') as first,
data.value('(XtraSerializer/property/property[@name="colSecondChoiceVendorPaymentTerms"]/property[@name="Visible"])[1]', 'bit') as second
from temp
sql fiddle demo
更新 2
如果你的数据类型是 text/varchar,试试这个:
select
c.data_xml.value('(XtraSerializer/property/property[@name="colFirstChoiceVendorPaymentTerms"]/property[@name="Visible"])[1]', 'bit') as first,
c.data_xml.value('(XtraSerializer/property/property[@name="colSecondChoiceVendorPaymentTerms"]/property[@name="Visible"])[1]', 'bit') as second
from temp as t
outer apply (select cast(t.data as xml) as data_xml) as c