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

Is this possible? In an events system an event can have multiple times. (ie,
Is this possible? Situation is that I want to store some XML in my
I'm trying to figure how to implement this in TSQL do update stuff set
Is this possible? I want to have the To:, Body, and an Attachment all
Is this possible? I am looking forward to a tutorial which explains the steps
Is this possible? I had troubles with SVN clients not being able to access
Is this possible? I can't find it anywhere.
Is this possible? I am creating a single base factory function to drive factories
Is this possible? I've followed the instructions from here ( http://www.jetbrains.net/confluence/display/TCD4/Setting+up+an+External+Database#SettingupanExternalDatabase-MicrosoftSQLServer2005 ) but I
Is this possible: myList = [] myList[12] = 'a' myList[22] = 'b' myList[32] =

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.