2013-02-02 54 views

回答

2

SQL Fiddle

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"/> | 
相關問題