I am having Xpath to delete from XML in an VARCHAR(MAX) variable, but XML.modify('delete '+@MyXpath)
give an error ,
The argument 1 of the XML data type method "modify" must be a string literal.
DECLARE @myXML XML,
@MyXpath VARCHAR(MAX)
-- Processing of Xpaths for components needed to remove
-- Adding those in @XpathsToRemove
SELECT TOP(1) @MyXpath = [XPATH]
FROM @XpathsToRemove
SET @myXML.modify('delete '+@MyXpath)
Is there any way to remove those components with Xpath available in @MyXpath variable ?
-- Edit Example XML
DECLARE @myXML XML ='<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget me this weekend!</body>
</note>'
,@MyXpath VARCHAR(MAX) = '//note/from'
-- There are many Xpaths and dynamically generated with some processing so I don't want to hardcode Xpath there
SET @myXML.modify('delete '+@MyXpath)
--This doesn't works too
-- SET @myXML.modify('delete "sql:variable("MyXPath")"')
SELECT @myXML