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

  • Home
  • SEARCH
  • 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 5932673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:52:00+00:00 2026-05-22T14:52:00+00:00

I’m attempting to create an xquery expression that will return all the subchild node

  • 0

I’m attempting to create an xquery expression that will return all the subchild node values. Now I get only the first subchild under each child.

I have the following XML:

<order>
    <child1>
      <subchild id="S1">
        <name type="primary">
          <first>NAOMI</first>
          <middle />
          <last>ADAMS</last>
          <suffix />
        </name>
      </subchild>
      <subchild id="S2">
        <name type="primary">
          <first>TOVER</first>
          <middle />
          <last>DALI</last>
          <suffix />
        </name>
      </subchild>
    </child1>
    <child2>
      <subchild id="V1">
        <year>2002</year>
        <make>PONTI</make>
        <model>AZTEK</model>
        <vin>3G7DA03E32S597676</vin>
      </subchild>
      <subchild id="V2">
        <year>2003</year>
        <make>HONDA</make>
        <model>CIVIC</model>
        <vin>2H94DA03E80S1538</vin>
      </subchild>
    </child2>
    <child3>
      <subchild id="A1">
        <house>7741</house>
        <street1>SAINT BERNARD ST</street1>
        <apartment />
        <city>PLAYA DEL REY</city>
        <state>CA</state>
        <postalcode>90293</postalcode>
      </subchild>
      <subchild id="A2">
        <house>2371</house>
        <street1>HANNUM DR</street1>
        <apartment />
        <city>MARINA DEL REY</city>
        <state>CA</state>
        <postalcode>90293</postalcode>
      </subchild>
    </child3>
  </order>

My result should look like :

  FirstName LastName    HouseNumber StreetName         City         SState  Zip    Year     Model   Make    VIN
   NAOMI     ADAMS        7741   SAINT BERNARD ST   PLAYA DEL REY     CA    90293   2002    PONTI   AZTEK   G7DA03E32S597676
   TOVER     DALI         2371    HANNUM DR         MARINA DEL REY    CA    90024   2003    HONDA   CIVIC   2H94DA03E80S1538

My query :

SELECT 
   FirstName, LastName, HouseNumber, StreetName, City, SState, Zip, Year, Model, Make, VIN
FROM 
   xmlTable 
OUTER APPLY 
(  
    SELECT  
       tbl.col.value('(child1/subchild/name/first)[1]','varchar(20)') AS FirstName,
       tbl.col.value('(child1/subchild/name/last)[1]','varchar(20)') AS LastName,
       tbl.col.value('(child1/subchild/name/middle)[1]','varchar(20)') AS MiddleName,
       tbl.col.value('(child3/subchild/house)[1]','varchar(20)') AS HouseNumber,
       tbl.col.value('(child3/subchild/street1)[1]','varchar(20)') AS StreetName,
       tbl.col.value('(child3/subchild/city)[1]','varchar(20)') AS City,
       tbl.col.value('(child3/subchild/state)[1]','varchar(20)') AS SState,
       tbl.col.value('(child3/subchild/postalcode)[1]','varchar(20)') AS Zip,
       tbl.col.value('(child2/subchild/model_year)[1]','varchar(20)') AS Year,
       tbl.col.value('(child2/subchild/model)[1]','varchar(20)') AS Model,
       tbl.col.value('(child2/subchild/make)[1]','varchar(20)') AS Make,
       tbl.col.value('(child2/subchild/vin)[1]','varchar(20)') AS VIN
    FROM 
       xmldocument.nodes('//order') AS tbl(col) 
   )  Y 

Thanks

  • 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-22T14:52:01+00:00Added an answer on May 22, 2026 at 2:52 pm
     
    DECLARE @x XML 
    SELECT @x = 'Your XML here'
    SELECT   
    tbl.col.value('(child1/subchild/name/first)[position() = sql:column("s.number")][1]','varchar(20)') AS FirstName, 
    tbl.col.value('(child1/subchild/name/last)[position() = sql:column("s.number")][1]', 'varchar(20)') AS LastName, 
    tbl.col.value('(child1/subchild/name/middle)[position() = sql:column("s.number")][1]', 'varchar(20)') AS MiddleName, 
    tbl.col.value('(child3/subchild/house)[position() = sql:column("s.number")][1]', 'varchar(20)') AS HouseNumber, 
    tbl.col.value('(child3/subchild/street1)[position() = sql:column("s.number")][1]', 'varchar(20)') AS StreetName, 
    tbl.col.value('(child3/subchild/city)[position() = sql:column("s.number")][1]', 'varchar(20)') AS City, 
    tbl.col.value('(child3/subchild/state)[position() = sql:column("s.number")][1]', 'varchar(20)') AS SState, 
    tbl.col.value('(child3/subchild/postalcode)[position() = sql:column("s.number")][1]', varchar(20)') AS Zip, 
    tbl.col.value('(child2/subchild/model_year)[position() = sql:column("s.number")][1]', 'varchar(20)') AS Year, 
    tbl.col.value('(child2/subchild/model)[position() = sql:column("s.number")][1]', 'varchar(20)') AS Model, 
    tbl.col.value('(child2/subchild/make)[position() = sql:column("s.number")][1]', 'varchar(20)') AS Make, 
    tbl.col.value('(child2/subchild/vin)[position() = sql:column("s.number")][1]', 'varchar(20)') AS VIN 
    FROM @x.nodes('/order') AS tbl(col) 
    CROSS JOIN master..spt_values s  
    WHERE type = 'P' AND number BETWEEN 1  
    AND col.query('count(child1/subchild)').value('.', 'INT')
     
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.