Hello,
I'm trying to pull out records that have certain values in the XML Data type field.
table def
ID int,
XMLcol xml
The data in the XMLcol field is such
The xquery I'm using requires that I use a 'singleton' because the I haven't typed the xml data against a schema collection (I have reasons not to).
I'm just trying to pull out the ids of the vets that have 'Lab' as a breed. I don't get the id back for this record because the 'Lab's are not the first Dog in the xml. HOw do I omit the '[1]' in my query without getting the dreaded error???:
"'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'"
Thanks for any insight...I'm fairly new to xquery and the sql XML data type
I'm trying to pull out records that have certain values in the XML Data type field.
table def
ID int,
XMLcol xml
The data in the XMLcol field is such
Code:
<Vet>
<DogDetail>
<breed>Poodle</breed>
<color>Brown</color>
<sex>male</sex>
</DogDetail>
<DogDetail>
<breed>Lab</breed>
<color>black</color>
<sex>male</sex>
</DogDetail>
<DogDetail>
<breed>Lab</breed>
<color>yellow</color>
<sex>female</sex>
</DogDetail>
</Vet>
The xquery I'm using requires that I use a 'singleton' because the I haven't typed the xml data against a schema collection (I have reasons not to).
I'm just trying to pull out the ids of the vets that have 'Lab' as a breed. I don't get the id back for this record because the 'Lab's are not the first Dog in the xml. HOw do I omit the '[1]' in my query without getting the dreaded error???:
"'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'"
Code:
select ID
from tablename (nolock)
where XMLcol.value('(/Vet/DogDetail/breed)[1]','varchar(50)') = 'Lab'
Thanks for any insight...I'm fairly new to xquery and the sql XML data type