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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:37:59+00:00 2026-05-13T09:37:59+00:00

How can I get the second column with the same column name using OPENXML

  • 0

How can I get the second column with the same column name using OPENXML in MSSQL 2005?

Here is the result set that I plan to get.

columnData1 columnData2

A B

C D

E F

DECLARE @hDoc int, @xmldata varchar(max)
SELECT @xmldata = 

'<?xml version="1.0" encoding="utf-8" ?>
<reportResponse>
<reportDataRow rowNum="1">
<columnData colNum="1">
  <data>A</data>
</columnData>
<columnData colNum="2">
  <data>B</data>
</columnData>
</reportDataRow>
<reportDataRow rowNum="2">
<columnData colNum="1">
  <data>C</data>
</columnData>
<columnData colNum="2">
  <data>D</data>
</columnData>
</reportDataRow>
<reportDataRow rowNum="3">
<columnData colNum="1">
  <data>E</data>
</columnData>
<columnData colNum="2">
  <data>F</data>
</columnData>
</reportDataRow>
</reportResponse>'

EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata

SELECT *
FROM OPENXML(@hDoc, '/reportResponse/reportDataRow',2)
WITH (columnData varchar(50) , columnData2 varchar(50) )


SELECT *
FROM OPENXML(@hDoc, '/reportResponse/reportDataRow/columnData',2)
WITH (data varchar(50))

EXEC sp_xml_removedocument @hDoc
  • 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-13T09:38:00+00:00Added an answer on May 13, 2026 at 9:38 am

    Thanks. I found the answer by using PIVOT. In my real case, I have more than 10 columns and thousands of rows, so it won’t be easy to self join. BTW, this is for parsing xml data set from PayPal reportEngineResponse. Here is the answer to share.

    DECLARE @hDoc INT, @xmldata VARCHAR(MAX)
    SELECT @xmldata = 
    
    '<?xml version="1.0" encoding="utf-8" ?>
    <reportResponse>
    <reportDataRow rowNum="1">
    <columnData colNum="1">
      <data>A</data>
    </columnData>
    <columnData colNum="2">
      <data>B</data>
    </columnData>
    </reportDataRow>
    <reportDataRow rowNum="2">
    <columnData colNum="1">
    <data>C</data>
    </columnData>
    <columnData colNum="2">
    <data>D</data>
    </columnData>
    </reportDataRow>
    <reportDataRow rowNum="3">
    <columnData colNum="1">
    <data>E</data>
    </columnData>
    <columnData colNum="2">
    <data>F</data>
    </columnData>
    </reportDataRow>
    </reportResponse>'
    
    EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata
    
    SELECT [1] as row1, [2] as row2
    FROM
    (SELECT *
    FROM OPENXML(@hDoc, '/reportResponse/reportDataRow/columnData',2)
    WITH (data VARCHAR(50) 
     ,rowNum INT       '../@rowNum'
     ,colNum INT       '@colNum')) P
    PIVOT
    (
    MAX(data)
    FOR colNum IN ([1],[2]) 
    )AS pvt
    
    EXEC sp_xml_removedocument @hDoc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'd use Kohana's has-many-through relationship. An example would be: class… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer PEP 8 contains all the answers. May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer You can use DeinitializeSetup() event for monitoring that. From documentation:… May 16, 2026 at 4:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two columns, the first column will have the name of a object,
I have a JS function that processes XML I GET from a server to
Here's a brain-twister for the SQL guys - can anyone think of a reason
My first post here, please be gentle. =) I work for a company that
I have been trying to get the unique values in each column of a
My ice:dataTable looks like below:- <ice:dataTable id=someTbl var=someVar value=#{someBean.someList} > <ice:column> <f:facet name=header> <ice:outputText
In my stored procedure I have to pass a table and column name which
I'm working on a sortable table, that is refreshed asynchronously when the column headers
Using MySQL, when I have a table with (for example) three keys (one primary,
We have a small project that involves automatically parsing some server/mail logs (among other

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.