我们有一个类似于此的xml列:
ROW1:
<a f="value1" b="value2" c="value3" d="value4" />
<a f="value5" b="value6" c="value7" d="value8" Case="value9" />
ROW2:
<a f="value1" b="value15" c="value16" d="value17" />
<a f="value10" b="value11" c="value12" d="value13" Case="value14" />
...
我们希望选择具有f="value1"
。
答案 0 :(得分:2)
MS SQL Server 2008架构设置:
create table YourTable
(
XMLColumn xml
)
insert into YourTable values('<a f="value1" b="value2" c="value3" d="value4" />
<a f="value5" b="value6" c="value7" d="value8" Case="value9" />')
insert into YourTable values('<a f="value1" b="value15" c="value16" d="value17" />
<a f="value10" b="value11" c="value12" d="value13" Case="value14" />')
查询1 :
select *
from YourTable
where XMLColumn.exist('a[@f = "value1"]') = 1
<强> Results 强>:
| XMLCOLUMN |
--------------------------------------------------------------------------------------------------------------------------
| <a f="value1" b="value2" c="value3" d="value4"/><a f="value5" b="value6" c="value7" d="value8" Case="value9"/> |
| <a f="value1" b="value15" c="value16" d="value17"/><a f="value10" b="value11" c="value12" d="value13" Case="value14"/> |