DECLARE @XmlDoc XML
SET @XmlDoc = '<root>
<emp>
<name>John</name>
<salary>22140</salary>
</emp>
<emp>
<name>Walter</name>
<salary />
</emp>
<emp>
<salary />
</emp>
</root>'
I want to check if salary node inside emp is empty or not, if its empty delete that node. Below is what I've tried. It deletes the entire emp tag inside of just the salary tag.
SET @XmlDoc.modify('delete //root/emp[salary = ""]')
Current Output:
<root>
<emp>
<name>John</name>
<salary>22140</salary>
</emp>
</root>
Expected Output:
<root>
<emp>
<name>John</name>
<salary>22140</salary>
</emp>
<emp>
<name>Walter</name>
</emp>
</root>