Reputation: 309
I have following xml content in a column,
<Certification name="ACT" type=""/>
<Certification name="CERTIFIED PEDIATRIC NURSE" type="Certification"/>
<Certification name="LICENSED VOCATIONAL NURSE (LVN)" type="License"/>
My question is when I find empty in 'type' atrribute , that single tag should be eleminated.
for example I need output like follows,
<Certification name="CERTIFIED PEDIATRIC NURSE" type="Certification"/>
<Certification name="LICENSED VOCATIONAL NURSE (LVN)" type="License"/>
In the above output empty 'type' attribute has been removed.
So could anyone suggest how to do it using sql query?
Upvotes: 0
Views: 551
Reputation: 1976
You should be able to do something like this...
DECLARE @xml as table(xmlData xml)
insert into @xml(xmlData)
select '<Certification name="ACT" type=""/><Certification name="CERTIFIED PEDIATRIC NURSE" type="Certification"/><Certification name="LICENSED VOCATIONAL NURSE (LVN)" type="License"/>'
SELECT xmlData.query('/Certification[@type!=""]') as filteredXml
FROM @xml T
As you've got it already in a table column you can just use the last select statement substituting @xml and xmlData with your table name and table field respectively
Upvotes: 1