2

I found the following which shows how to delete an attribute from XML in SQL Server: How to delete an attribute from an XML variable in sql server 2008?

But I would like to delete two attributes at once. I tried something like the following:

UPDATE TABLE SET
  xmlField.modify('delete  (/clue_personal_auto/@attr1)[1]'),
  xmlField.modify('delete  (/clue_personal_auto/@attr2)[1]')
 WHERE compare = 357

But I get an error that the same column cannot be modified more than once during an update. Is there a way to delete both within once statement, or should I just run two separate updates?

1
  • 1
    If you post code, XML or data samples, PLEASE highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it! Commented Jun 19, 2012 at 15:04

1 Answer 1

3
UPDATE TABLE SET
  xmlField.modify('delete (/clue_personal_auto/@*[local-name()=("attr1", "attr2")])')
 WHERE compare = 357

SE-Data

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.