Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:41:49+00:00 2026-06-01T00:41:49+00:00

I have an XML valued column that has multiple parent nodes. I need to

  • 0

I have an XML valued column that has multiple “parent” nodes. I need to insert a “child” node into each parent node. If I use

UPDATE mytable SET mycolumn.modify('insert <child/> into (//parent)[1]')

, then I’m inserting a child node into the first parent only.

How do I insert a child in every parent with a single query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:41:50+00:00Added an answer on June 1, 2026 at 12:41 am

    I believe the easiest way to accomplish this is to reconstruct the XML with a SELECT statement using CROSS APPLY and FOR XML.

    Here’s an example, hope it makes sense. With this approach, you could also JOIN to another table for the data you want to insert into the <child2 /> node making this solution quite flexible.

    DECLARE @t TABLE ( Document XML )
    INSERT INTO @t
    SELECT '<root><parent><child1>first row data</child1></parent><parent><child1>second row data</child1></parent></root>'
    
    SELECT
        ref.value('child1[1]', 'varchar(max)') as child1, 
        'something to insert' as child2
    FROM @t CROSS APPLY Document.nodes('//parent') R(ref)
    FOR XML PATH('parent'), ROOT('root')
    

    Results

    <root>
      <parent>
        <child1>first row data</child1>
        <child2>something to insert</child2>
      </parent>
      <parent>
        <child1>second row data</child1>
        <child2>something to insert</child2>
      </parent>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that has a collection of objects. Each object has
I have an xml column in my SQL Server database that has records in
I have a table with a column named Description that contains XML like: <Parent>
I have created a table that has a strongly type XML column in SQL2008
I have an XML file consisting of Name/Value pairs that I need in a
I have SQL table that has a varchar(8) column that occasionally has binary data
I'm trying to query a table which has a column that contains straight xml
I have an xml column ExportTemplate in a table that holds an xsl template
I have a stored proc that inserts XML into an underlying table. Unfortunately the
I have an XML Document and I need to convert it into an Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.