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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:11:33+00:00 2026-05-21T05:11:33+00:00

Is this possible in TSQL? I am feeding this structure in via an xml

  • 0

Is this possible in TSQL?

I am feeding this structure in via an xml param. And I need to set it into a temp table.

DECLARE @xml xml
SET @xml = '<Events>
            <Event id="8">
                <Responses>
                    <Response id="59">
                        <Loe>
                            <Id>89</Id>
                        </Loe>
                    </Response>
                    <Response id="60">
                        <Loe>
                            <Id>89</Id>
                            <Id>90</Id>
                            <Id>88</Id>
                            <Id>87</Id>
                        </Loe>
                    </Response>
                </Responses>
            </Event>
        </Events>';

Trying to display it like:

EventId    ResponseId     LoeId
8          59             89
8          60             89
8          60             90
8          60             88
8          60             87

I tried to use this query, but it throws an error.

SELECT
  [data].value('../../@id','varchar(100)') AS EventId,
  [data].value('@id','varchar(100)') AS ResponseId,
  [data].value('Loe/Id','varchar(100)') AS LoeId
FROM @xml.nodes('/Events/Event/Responses/Response') as Test([data])

But if I remove the LoeId it works and I get this:

EventId    ResponseId
8          59             
8          60             

What I am doing wrong? How do I address the Loe->Id in the query?

I am using MSSQL 2008. Do you have any ideas?

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-21T05:11:33+00:00Added an answer on May 21, 2026 at 5:11 am

    this should do it:

    SELECT
        event.value('@id', 'int') AS Event,
        response.value('@id','int') AS Response,
        id.value('.','int') AS LoeId
    FROM
        @xml.nodes('Events/Event') AS t1(event) cross apply
        t1.event.nodes('Responses/Response') AS t2(response) cross apply
        t2.response.nodes('Loe/Id') AS t3(id)
    ORDER BY Event, Response, LoeId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: TSQL Writing into a Temporary Table from Dynamic SQL ALTER PROCEDURE [dbo].[usp_ServicesStats1](@PERIOD
I found this tsql query that shows the xml schema of a table and
Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
Possible Duplicate: T-SQL Group Rows Into Columns I have a table _data that is
I'm trying to figure how to implement this in TSQL do update stuff set
Possible Duplicate: TSQL How do you output PRINT in a user defined function? This
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
Is this possible if I click on an anchor link to simulate as if
Is this possible? My code works on Firefox. I can also get webkit to
Is this possible? function testObj(testArg) { //Do obj stuff here } testObj.prototype.addFn = function()

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.