Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding node to XML data using Xquery

Posted on 2011-09-19
1
Medium Priority
?
349 Views
Last Modified: 2012-05-12
Is there a way to add a node to an XML string using Xquery?

For example:

<node1>test1</node1>
<node2>test2</node2>

The XML string is stored in a SQL table so I would need to extract the string, add the node and save the string back to the table.

0
Comment
Question by:felkamau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36563757
felkamau,

Maybe you want to look at the insert capabilities of XML.modify() in SQL Server.
Here is an example:
DECLARE @xml XML;
SET @xml = '<node1>test1</node1><node2>test2</node2>';

SET @xml.modify('insert <node3>test3</node3> as last into (/)');

SELECT @xml;

Open in new window


Hope that helps!

Best regards and happy coding,

Kevin
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question