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]

4

1 回答 1

2

愚蠢的 XQuery!(或者可能是我)。

您需要放置[1]括号的外部:

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

应该

into (Root/Collection/Item[@No="360"])[1]
于 2013-02-22T11:22:46.303 回答