Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic xml insert in sql server 2005

Status
Not open for further replies.

jamesagnew

Programmer
Feb 7, 2002
13
FR
Hi

I'm trying to insert an xml node containing a dynamically generated value in SQL Server 2005.

Here's what I've got so far:


declare @x nvarchar(100)

set @x = 'abc123'

UPDATE tbl_tree
SET theTree.modify('replace value of (/tree[1]/branch[1]/@name) with @x')

This doesn't work of course because it expects "" around the value that is being added (@x)

I've tried creating a string such as

@str='replace value of (/tree[1]/branch[1]/@name) with "'+@x + '"'

and EXEC() it but that still doesn't work.

Any ideas?

Thanks, James
 
Well I found the answer - I hope this helps someone...

SET theTree.modify('replace value of (/tree[1]/branch[1]/@name) with sql:variable("@x")')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top