過濾

2013-02-19 71 views
1
<Root> 
    <Sub> 
     <Name>a</Name> 
     <Value>1</Value> 
    </Sub> 
    <Sub> 
     <Name>b</Name> 
     <Value>2</Value> 
    </Sub> 
</Root> 

我知道我可以做一個過濾

SELECT * FROM table WHERE column.exist('/Root/Sub[Name="a" and Value="1"]') = 1 

但我怎麼兩個名稱/值對過濾器? a/1和b/2?

+0

類似的問題在這裏回答: http://stackoverflow.com/questions/6162273/search-for-multiple-values-in-xml-column-in -sql – alxK 2015-02-07 16:11:24

回答

2

如何:

SELECT * FROM table WHERE (column.exist('/Root/Sub[Name="a" and Value="1"]') = 1 OR (column.exist('/Root/Sub[Name="b" and Value="2"]') = 1)

注意額外的括號。

-1

這將如預期:

SELECT * 
    FROM TableName 
WHERE XMLColumnName.Exist('/Root/Sub[Id = "IdValue"][LimitType = "LimitTypeName"]') = 1