RE: How can I replace a value in xml with .modify from the variable?
- From: "Kevin"<kevin.kraemer@xxxxxxxxxxxxxxxx>
- Date: Wed, 22 Nov 2006 14:55:20 GMT
Thanks for your help.
I am trying to modify a value within an xml. I found that this can be done with .modify but I must use literal for modify command. I need it variablized. Is there any way to do it without sp_executesql?
thanks
declare
@xml varchar(max)
,@xml1 xml
, @ConversationHandle char(36)
set @xml= '<Tasks><row ConversationHandle="" olnID="5981"/></Tasks>'
SET @xml1 = @xml
SET @ConversationHandle = newid()
This is what I want but using the xml .modify function
select cast(@xml as xml), cast(REPLACE( @xml, 'ConversationHandle=""', 'ConversationHandle="' + @ConversationHandle + '"') as xml)
SET @xml1.modify('
replace value of (/Tasks/row/@ConversationHandle)[1]
with "boo"
')
SELECT @xml1
DECLARE @m varchar(1000)
SET @m ='
replace value of (/Tasks/row/@ConversationHandle)[1]
with "' + cast(@ConversationHandle as char(36)) + '"'
SET @xml1.modify(@m) -- this errors
SELECT @xml1
Thanks for your help.
I am trying to modify a value within an xml. I =
found that=20
this can be done with .modify but I must use literal for modify command. =
I need=20
it variablized. Is there any way to do it without =
sp_executesql?
thanks
declare
@xml varchar(max)
,@xml1 xml
, @ConversationHandle char(36)
set @xml=3D ''
SET @xml1 =3D @xml
SET @ConversationHandle =3D newid()
This is what I want but using the xml .modify=20
function
select cast(@xml as xml), cast(REPLACE(=20
@xml, =
'ConversationHandle=3D""', 'ConversationHandle=3D"' + @ConversationHandle + '"') as xml)
SET @xml1.modify('
replace value of (/Tasks/row/@ConversationHandle)[1]
with "boo"
')
SELECT @xml1
DECLARE @m varchar(1000)
SET @m =3D'
replace value of (/Tasks/row/@ConversationHandle)[1]
with "' + cast(@ConversationHandle as char(36)) + '"'
SET @xml1.modify(@m) -- this =
errors
SELECT =
@xml1
You can easily do this using SQL variables in the XQuery literal
SET @m ='
replace value of (/Tasks/row/@ConversationHandle)[1]
with sql:variable("@ConversationHandle")'
BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
.
- References:
- Prev by Date: RE: Thoughts on storing address data with XML data type?
- Next by Date: SQLXML encoding setting
- Previous by thread: Re: How can I replace a value in xml with .modify from the variable?
- Next by thread: Re: XML - Am I missing something?
- Index(es):
Relevant Pages
|