Quantcast
Channel: XML replace problem
Viewing all articles
Browse latest Browse all 3

XML replace problem

$
0
0

I have two similar sources.  One sends me an Equipment-Type, the other sends a blank Equipment-Type but also sends an Equipment-Code.

I convert the Equipment Code to an Equipment-Type, then I try to update the XML with the Equipment-Type.  I can then pass this on to a common processing sp.

But the Xml.replace value will not work.

This is a subset of my code.

declare @xml xml ='<Tranx><InternalReference>1131457</InternalReference><EquipList><Equipment><EquipType>150</EquipType>		<Qty>111</Qty></Equipment><Equipment><EquipCode>1683</EquipCode><EquipType></EquipType><Qty>222</Qty></Equipment><Equipment><EquipType>172</EquipType><Qty>333</Qty></Equipment></EquipList></Tranx>' 

-- display the input before the change
Select	nref.value('EquipType[1]',		'nvarchar(50)')	as Equip,
		nref.value('Qty[1]',			'varchar(50)' ) as QTY	
FROM   @xml.nodes('/Tranx/EquipList/Equipment') AS R(nref)  

			
declare
@Instance    int = 2,
@TempEquip	varchar(10) = 'NewValue'

SET @xml.modify('replace value of (/Tranx/EquipList/Equipment[sql:variable("@Instance")]/EquipType[1]/text()   )[1]  with sql:variable("@TempEquip") ') 
-- display the input AFTER the change			
Select	nref.value('EquipType[1]',		'nvarchar(50)')	as Equip,
		nref.value('Qty[1]',			'varchar(50)' ) as QTY	
FROM   @xml.nodes('/Tranx/EquipList/Equipment') AS R(nref)  

Any help would be gretly appreciated.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images