sql server - Read XML child node attributes using SQL query -


i have 1 xml column (criteria) in table (qualifications) contains different xml:

<training id="173"><badge id="10027" /><badge id="10028" /></training> <book category="hobbies , interests" propertyname="c#" categoryid="44" /> <sport category="hobbies , interests" propertyname="cricket" categoryid="46" /> <education id="450" school="jai ambe vidyalaya"></education> 

i want read "badge" node "id" attributes nodes under "training" node.

can help?

ids of badge elements inside training only

select t.c.value('.', 'int') id qualifications q     cross apply q.criteria.nodes('//training[badge]/badge[@id]/@id') t(c) 

ids of badge elements anywhere (not inside training)

select t.c.value('.', 'int') id qualifications q     cross apply q.criteria.nodes('//badge[@id]/@id') t(c) 

if criteria column nvarchar type, can cast xml as:

select t.c.value('.', 'int') id qualifications q     cross apply (select convert(xml, q.criteria) xmlcriteria)     cross apply a.xmlcriteria.nodes('//training[badge]/badge[@id]/@id') t(c) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -