0

I am attempting to add an attribute to a node in an XML column in SQL Server.

UPDATE
    TableName
SET Metadata.modify('
    insert attribute MyAttribute{"01b9cd0b-bfed-436f-bc58-57d2fddd9211"}
    into (Root/Collection/Item[@No="360"][1])
')
WHERE
    TableName.Id = 1

I get the following error...

Msg 2226, Level 16, State 1, Line 4 XQuery
[TableName.Metadata.modify()]: The target of 'insert' must be a single node, found 'element(Item,xdt:untyped) *'

But I thought my selection would return a single item, given the [1]

1 Answer 1

2

Stupid XQuery! (Or possibly me).

You need to place the [1] outside of the brackets:

into (Root/Collection/Item[@No="360"][1])

Should be

into (Root/Collection/Item[@No="360"])[1]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.