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 6759255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:54:51+00:00 2026-05-26T13:54:51+00:00

I have a table with an XML Field. The XML Field’s Schema is something

  • 0

I have a table with an XML Field. The XML Field’s Schema is something similar to this…

<Root>
  <Parent>
    <Child>
      <SomeValue>1</SomeValue>
    </Child>
    <Child>
      <SomeValue>1</SomeValue>
    </Child>
  </Parent>

I know how to get the first, second, Nth SomeValue using this…

SELECT      
Child.value('(SomeValue)[1]', 'int')
FROM XMLField.nodes("/Root/Parent/Child[1]") AS N(Child) 

I’m trying to use an Insert Into statement to get all of the SomeValue nodes values into a table. The problem is that there could be multiple Child elements per Parent and I only know how to grab one at a time. Is there an easy way of accomplishing this without looping logic? (Each SomeValue value should be its own record in the table I’m inserting into).

Extra Credit: The example I showed gets the first SomeValue value from the first Child element of a single XML Field. Your answer would be extra helpful if you could come up with a solution that not only grabs all of the SomeValue values from a field of a single record, but instead all of the SomeValue values from that field in every record of a table.

  • 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-05-26T13:54:52+00:00Added an answer on May 26, 2026 at 1:54 pm
    declare @T table (XMlField xml)
    
    insert into @T values
    ('<Root>
      <Parent>
        <Child>
          <SomeValue>1</SomeValue>
        </Child>
        <Child>
          <SomeValue>2</SomeValue>
        </Child>
      </Parent>
    </Root>')
    
    insert into @T values
    ('<Root>
      <Parent>
        <Child>
          <SomeValue>3</SomeValue>
        </Child>
        <Child>
          <SomeValue>4</SomeValue>
        </Child>
      </Parent>
    </Root>')
    
    select X.N.value('SomeValue[1]', 'int') as SomeValue
    from @T as T
      cross apply T.XMLField.nodes('/Root/Parent/Child') as X(N)
    

    Result:

    SomeValue
    -----------
    1
    2
    3
    4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML field in SQL table like this <Root> <Name>Apollo</Name> <Code>1000</Code> <Code>2000</Code>
I'm trying to format a table from XML. Lets say I have this line
I have this XML in a column in my table: <keywords> <keyword name=First Name
I have a table that contains some meta data in an XML field. For
I have a SQL table with some normal fields and one xml-type field. I
I have a table in a MySql database with a datetime field. This is
I have a table called People one of the columns is an xml field
I have a table in SQL Server 2000 with a text field containing XML
I have an stored procedure that works on an table that contains xml field,
Say I have a table called xml that stores XML files in a single

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.