There is no direct approach to replace a full node with another.
But you can delete it and insert a new one:
DECLARE @xmlSource AS XML = '<Root><Transactions><ReplaceMe>This information should be gone</ReplaceMe></Transactions></Root>'
DECLARE @xmlInsert AS XML = '<NewNode>New Information</NewNode>'
DECLARE @NodeName NVARCHAR(500) = 'ReplaceMe'
SET @xmlSource.modify('delete /Root/Transactions/*[local-name(.) eq sql:variable("@NodeName")]');
SELECT @xmlSource;
SET @xmlSource.modify('insert sql:variable("@xmlInsert") into (/Root/Transactions)[1]');
SELECT @xmlSource;
Result
<Root>
<Transactions>
<NewNode>New Information</NewNode>
</Transactions>
</Root>
UPDATE General Solution
From your comments, I understand that you have no idea about XML, you just need to replace one node, where you know the name with another node ...
This solution is line-based (which is super ugly anyway) and has some disadvantages:
- If there are several nodes with this name, only the first one will be executed
- node ,
- xml
CDATA, XML . , ...
, XML NVARCHAR . .
, node . , ...
DECLARE @xmlSource AS XML = '<Root><Transactions><ReplaceMe>This information should be gone</ReplaceMe></Transactions></Root>'
DECLARE @xmlInsert AS XML = '<NewNode>New Information</NewNode>'
DECLARE @NodeName NVARCHAR(500) = 'ReplaceMe'
SELECT
CAST(
REPLACE(CAST(@xmlSource AS NVARCHAR(MAX))
,CAST(@xmlSource.query('//*[local-name(.) eq sql:variable("@NodeName")][1]') AS NVARCHAR(MAX))
,CAST(@xmlInsert AS NVARCHAR(MAX))
)
AS XML)