1
<Root>
    <Sub>
        <Name>a</Name>
        <Value>1</Value>
    </Sub>
    <Sub>
        <Name>b</Name>
        <Value>2</Value>
    </Sub>
</Root>

I know I can do a

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

but how do I filter on both Name/Value pairs? a/1 and b/2?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Shawn
  • 2,356
  • 6
  • 48
  • 82
  • Similar question answered here: http://stackoverflow.com/questions/6162273/search-for-multiple-values-in-xml-column-in-sql – alxK Feb 07 '15 at 16:11

2 Answers2

2

How about:

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)

Note the additional parentheses.

jokeefe
  • 1,836
  • 4
  • 22
  • 27
-1

This will work as expected:

SELECT *
  FROM TableName
 WHERE XMLColumnName.Exist('/Root/Sub[Id = "IdValue"][LimitType = "LimitTypeName"]') = 1
Pang
  • 9,564
  • 146
  • 81
  • 122