I want to add two new attributes for all nodes. The attributes name and values are the same for all elements.
I have the following XML structure:
<question id="1001"></question>
<question id="1002"></question>
<question id="1003"></question>
<question id="1004"></question>
and want to transform it as follows:
<question id="1001" test1="1" test2="2"></question>
<question id="1002" test1="1" test2="2"></question>
<question id="1003" test1="1" test2="2"></question>
<question id="1004" test1="1" test2="2"></question>
I was not able to find an example in the documentation of how multiple attributes are added,so I started with adding only the first one:
SELECT T.c.modify('insert attribute test1 {"1"} into (/question)[1]')
FROM @SetQuestionsAndAnswersDetailsXML.nodes('/question') T(c)
But I get the following error:
Msg 8137, Level 16, State 1, Line 89
Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.
Has anyone have an idea what I am doing wrong?