SQL小提琴
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
结果:
| 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"/> |