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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:27:32+00:00 2026-06-12T11:27:32+00:00

I need further assistance with extracting records from XML and loading it into a

  • 0

I need further assistance with extracting records from XML and loading it into a SQL Server table.

I have this as my @xml:

<admin submitter_id="login0" effective_date="mm/dd/yyyy">
<rec effected_id="login1" adjustment="100.00" type="foo">
<reason reason_id="1" />
<reason reason_id="2" />
</rec>
<rec effected_id="login2" adjustment="50.00" type="bar">
<reason reason_id="3" />
</rec>
</admin>

I need this from a result set:

login0, login1, mm/dd/yyyy, 100.00, foo, 1
login0, login1, mm/dd/yyyy, 100.00, foo, 2
login0, login2, mm/dd/yyyy, 50.00, bar, 3

Does that make sense? The adjustment to the reason_id is one to many. I have figured out how to extract all the values except for the second line. I can only obtain the first reason_id and then it proceeds to the next record. I think this can be beaten with a CROSS APPLY but I cannot get it to work. Please help!

oh, I may also have received bogus XML. So if that’s wrong, please tell me!

  • 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-12T11:27:33+00:00Added an answer on June 12, 2026 at 11:27 am

    How about something like

    DECLARE @Xml XML
    
    SELECT @Xml = '<admin submitter_id="login0" effective_date="mm/dd/yyyy"> 
    <rec effected_id="login1" adjustment="100.00" type="foo"> 
    <reason reason_id="1" /> 
    <reason reason_id="2" /> 
    </rec> 
    <rec effected_id="login2" adjustment="50.00" type="bar"> 
    <reason reason_id="3" /> 
    </rec> 
    </admin>'
    
    SELECT  @Xml,
            A2.B.value('(../../@submitter_id)[1]','VARCHAR(50)'),
            A2.B.value('(../@effected_id)[1]','VARCHAR(50)'),
            A2.B.value('(../../@effective_date)[1]','VARCHAR(50)'),
            A2.B.value('(../@adjustment)[1]','FLOAT'),
            A2.B.value('(../@type)[1]','VARCHAR(50)'),
            A2.B.value('(@reason_id)[1]','INT')
    FROM    @XML.nodes('//admin/rec/reason')  A2(B)
    

    SQL Fiddle DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex SQL Query, that needs to be filtered further. Part of
I have a table of people who need help, and a table of people
I've asked this already but I need further knowledge. I'm trying to link two
This question is a supplement to an earlier question. If you need further background,
I have this strange problem I need some help with. This menu code goes
I need to read webpage and store its content in string for further processing.
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need some regular expressions help. So far I have my code working to allow
Need just a push in the right direction with this. I'm building a multi-language

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.