I want to update multiple XML nodes in single Update query
XML:
<TransmissionData>
<HolderName>Tony Chase</CardHolderName>
<Type>VS</CardType>
<TransactionDetails>
<TransactionId />
</TransactionDetails>
<ValueType>CAPT</ValueType>
</TransmissionData>
This is what I have tried:
DECLARE @Type nVarchar(10) = 'MS'
DECLARE @ValueType nVarchar(10) = 'OPT'
DECLARE @TransactionId bigint = 122344555
UPDATE
Table1
SET
Data.modify('replace value of (/TransmissionData/CardType/text())[1] with sql:variable("@Type")'),
Data.modify('replace value of (/TransmissionData/ValueType/text())[2] with sql:variable("@ValueType")'),
Data.modify('replace value of (/TransmissionData/TransactionDetails/TransactionId/text())[1] with sql:variable("@TransactionId")')
WHERE
RequestId = 2133831593
It works only for single Update, if I use more then one like ValueType and TransactionId, it shows an error. Please help me - how to update this?
Msg 264, Level 16, State 1, Line 7
The column name 'TransmissionData' is specified more than once in the SET clause or column list of an INSERT. A column cannot be assigned more than one value in the same clause. Modify the clause to make sure that a column is updated only once. If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.