问题
I'm trying to create a function able to rename an element within XML columns.
The function should be something as
create function dbo.fnRenameElement(
@doc xml
, @parentElementPath nvarchar(MAX)
, @oldElementName nvarchar (255)
, @newElementName nvarchar (255)
)
returns ... (whatever, not really interested actually)
Something I would use in this way
Select
dbo.fnRenameElement(MyTable.MyXmlColumn, 'some/xml/path/', 'ElementNameToReplace', 'NewElementName')
Where
...
I had a look at this answer, I have a similar need but I also need to have newName, OldName and xmlPath as variable, which I'm not able to work out.
It seems (am I wrong?) that I cannot use string variables withing query
, modify
, insert
XQuery functions
I want to avoid any "convert to string - replace old with new element name - convert back to xml": this does not work if "oldElementName" can appear anywhere else within the xml column data
来源:https://stackoverflow.com/questions/59072683/function-for-renaming-an-element-in-sql-server-xml