I am trying to pass a local variable within a XML.modify function as a node within my SQL Script as the xml trying to be modified is dynamic. See code below
DECLARE
@XML VARCHAR(MAX) = 'ns:Messages/ns:T001.0_NewSPIDRequests/ns:T001.0_NewSPIDRequest/ns:D2009_SWConnectionRef'
;WITH XMLNAMESPACES('urn:bridgeall-com:cmaservice:data:v3' AS ns)
UPDATE XMLMessageFeeder
SET theXML.modify('replace value of (/ns:Submission/*[local-name(.) = sql:variable("@XML")]/text())[1] with ("New Value")')
SELECT theXML
FROM XMLMessageFeeder
The issue I'm having is the above doesn't update the the value of that node yet if I was to set the replace as the following:
SET theXML.modify
('
replace value of (/ns:Submission/ns:Messages/ns:T001.0_NewSPIDRequests/ns:T001.0_NewSPIDRequest/ns:D2009_SWConnectionRef/text())[1]
with ("New Value")
')
This works. From my knowledge (which is little) they are both passing the same replace code yet using a variable doesnt seem to work.
Can someone point me in the right direction?
EDIT Answer can be found below in the comments.