0

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?

1
  • 1
    Is this to be a permanent change or just changing the result returned in a SELECT (but leaving the data as-is within the table)? Commented Jun 19, 2014 at 13:01

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.