I am storing a XML data into a table called BikeTable
. The XML data is coming from an object that is being serialized using .Net serializer.
BikeTable would look like this :
Id - UniqueIdentifier
XmlData - XML
The XML stored in the XmlData
column looks like this :
Record 1 :
<Bike>
<Material>
<Cage>EIECH</Cage>
<Mpn>B258-C436-B001</
</Material>
<Roles>
<string>Race</string>
<string>Mountain</string>
<string>City</string>
</Roles>
</Bike>
Record 2 :
<Bike>
<Material>
<Cage>ABCDE</Cage>
<Mpn>B258-C436-B001</Mpn>
</Material>
<Roles>
<string>Race</string>
</Roles>
</Bike>
I want to be able to find the records in my table that will contain for example Race and Mountain.
Example if I want the Ids of the record that contains 'Road'and 'Mountain" the only way I found is like this :
select Id
from BikeTable
where XmlData.exist('/Bike/Roles/string[contains(., "Road")]') = 1
or XmlData.exist('/Bike/Roles/string[contains(., "Mountain")]') = 1
I don't like this option because it forces me to generate the query if I want to find records that would match one or several roles. Roles can contains unlimited number of values and I need to be able to find the records that will one or more values. Ex : records containing Race, records containing Race or Montain, records containing City, records containing City and Mountain etc.
Is there any way to know if a list contains several values?