I am trying to update a table using an xml.
UPDATE dbo.M_Picture
SET Sequence = T.c.query('Sequence')
FROM dbo.M_Picture pic
INNER JOIN @xml.nodes('/pictures/picture') T(c)
ON pic.PictureId = T.c.query('pictureId') --I guess issue is in this line
The XML I am using is
<pictures>
<picture>
<pictureId>30</pictureId>
<Sequence>4</Sequence>
</picture>
<picture>
<pictureId>31</pictureId>
<Sequence>4</Sequence>
</picture>
</pictures>
The error message I am getting is
Operand type clash: xml is incompatible with int
And it makes sense because in
pic.PictureId=T.c.query('pictureId')
pictureId is int
How to sort this out?
Try this:
Use the
.value()method on the XML – that returns a scalar type (likeint)Also: I’m not sure if you really want to assign the XML fragment
<Sequence>4</Sequence>to your columnSequence– or whether you want to use the.value()method there, too!