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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:01:03+00:00 2026-05-18T00:01:03+00:00

I have an xml document which i want to pass as a parameter to

  • 0

I have an xml document which i want to pass as a parameter to a stored procedure
the xml looks like this

<root> 
    <EMPLOYEE ID= 100> 
     <PERIOD>AUG-2010</PERIOD>
        <earnings> 
               <title>BASIC</title>
        <amount>2000</amount>
        <title>HRA</title>
        <amount>1000</amount>
        <title>CONVEYANCE</title>
        <amount>500</amount>
        </earnings> 
    </EMPLOYEE> 
     <EMPLOYEE ID= 101> 
    <PERIOD>AUG-2010</PERIOD>
          <earnings> 
               <title>BASIC</title>
        <amount>2000</amount>
        <title>HRA</title>
        <amount>400</amount>
        <title>CONVEYANCE</title>
        <amount>500</amount>
        </earnings> 
    </EMPLOYEE> 

 <EMPLOYEE ID= 102> 
    <PERIOD>AUG-2010</PERIOD>
          <earnings> 
               <title>BASIC</title>
        <amount>2000</amount>
        <title>HRA</title>
        <amount>800</amount>
        <title>CONVEYANCE</title>
        <amount>5000</amount>
        </earnings> 
 </EMPLOYEE> 
</root>

I need to store the above information to 2 tables ie: payslipdetails and payheaddetails.
I think I have to loop through the xml doc . the outer loop gives me the employee id and period then I insert into the payslipdetails table with those fields and then get into the inner loop and I want to insert the payheaddetailswith the same employeeid and all his earnings deatls like

empid   title  amount
100     basic   2000
100     hra     1000
100     conveyance   500

then I go to the outer loop and get the next employee id and repeat the same thing

How can I go to the inner child xml any ways like openxml etc..??

  • 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-18T00:01:03+00:00Added an answer on May 18, 2026 at 12:01 am

    First of all, this is not valid XML:

    <EMPLOYEE ID= 102> 
        <PERIOD>AUG-2010</PERIOD>
              <earnings> 
                   <title>BASIC</title>
            <amount>2000</amount>
            <title>HRA</title>
            <amount>800</amount>
            <title>CONVEYANCE</title>
            <amount>5000</amount>
            </earnings> 
     </EMPLOYEE> 
    

    The ID= attribute must be followed immediately by data – preferably in double quotes – this is valid:

    <EMPLOYEE ID="102"> 
    

    Next: the fact that you have multiple <title>..</title><amount>...</amount> tag pairs inside your <earnings> tag without a container around them makes parsing next to impossible (or really messy)…..

    <earnings> 
       <title>BASIC</title>
       <amount>2000</amount>
       <title>HRA</title>
       <amount>800</amount>
       <title>CONVEYANCE</title>
       <amount>5000</amount>
    </earnings> 
    

    If ever possible, try to change this to something like this:

    <earnings> 
       <earning>
         <title>BASIC</title>
         <amount>2000</amount>
       </earning>
       <earning>
         <title>HRA</title>
         <amount>800</amount>
       </earning>
       <earning>
         <title>CONVEYANCE</title>
         <amount>5000</amount>
       </earning>
    </earnings> 
    

    That would be much easier to handle!

    If you had that extra <earning> container that encloses the <title>/<amount> pair, then you could easily write this XQuery statement and handle all your needs without messy, slow cursors alltogether:

    SELECT
        RootData.Employee.value('(@ID)[1]', 'int') AS 'EmployeeID',
        E.E2.value('(title)[1]', 'varchar(50)') AS 'Title',
        E.E2.value('(amount)[1]', 'decimal(18,4)') AS 'Amount'
    from
        (your XML column).nodes('/root/EMPLOYEE') AS RootData(Employee)
    CROSS APPLY
        RootData.Employee.nodes('earnings/earning') AS E(E2)
    

    and you’d get an output something like this:

    EmployeeID  Title         Amount
      100       BASIC          2000.0000
      100       HRA            1000.0000
      100       CONVEYANCE      500.0000
      101       BASIC          2000.0000
      101       HRA             400.0000
      101       CONVEYANCE      500.0000
      102       BASIC          2000.0000
      102       HRA             800.0000
      102       CONVEYANCE     5000.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Picture the following situation. I have an XML document as follows, <Form> <Control Type=Text
I have XML data as a string which has to parsed, I am converting
I have a zip file which can contain any number of zipfiles inside it
I'm using JavScript and jQuery to read an XML document and subsequently use the
(Edited to add an example and hopefully make it a bit clearer) I'm mainly
I am having trouble using the XSLT 1.0 function library (since .NET/Visual Studio doesn't
I'm writing a client for a group of RESTful services. The body of the
Is there a way to include some aspx/ascx markup in a DLL and use
As part of the base class for some extensive unit testing, I am writing
How do I cast an instance of an object and actually make it that

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.