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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:19:17+00:00 2026-06-14T04:19:17+00:00

I need a nudge in the right direction here. Simplified data looks like: ItemId|ItemName|ObjectId|ObjectName

  • 0

I need a nudge in the right direction here. Simplified data looks like:

ItemId|ItemName|ObjectId|ObjectName
    1 |  Alpha |      1 |  Alpha-1
    1 |  Alpha |      2 |  Alpha-2
    2 |   Beta |      3 |   Beta-1
    2 |   Beta |      4 |   Beta-2

And my target xml needs to be:

<Root>
  <Items>
    <Item>
      <id>1</id>
      <name>Alpha</name>
    </Item>
    <Item>
      <id>2</id>
      <name>Beta</name>
    </Item>
  </Items>
  <Objects>
    <Object>
      <id>1</id>
      <item_id>1</item_id>
      <name>Alpha-1</name>
    </Object>
    <Object>
      <id>2</id>
      <item_id>1</item_id>
      <name>Alpha-2</name>
    </Object>
    <Object>
      <id>3</id>
      <item_id>2</item_id>
      <name>Beta-1</name>
    </Object>
    <Object>
      <id>4</id>
      <item_id>2</item_id>
      <name>Beta-2</name>
    </Object>
  </Objects>
</Root>

I am having trouble with the FOR XML statement syntax that will allow this kind of break out between the Items section and the Objects section. I know how to code each section individually (the Objects one anyway), but do not know how to get this stacked output. Can I do this from the single View shown here or do I need split things up and them splice the xml back together somehow?

  • 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-14T04:19:18+00:00Added an answer on June 14, 2026 at 4:19 am

    Yes, you need to “split things up and then splice the xml back together somehow?”. You need two queries, one for Items and one for Objects.
    Here is a way to do just that.

    declare @T table
    (
      ItemId int,
      ItemName varchar(10),
      ObjectId int,
      ObjectName varchar(10)
    )
    
    
    insert into @T
    select    1 ,  'Alpha',       1,   'Alpha-1' union all
    select    1 ,  'Alpha',       2,   'Alpha-2' union all
    select    2 ,   'Beta',       3,    'Beta-1' union all
    select    2 ,   'Beta',       4,    'Beta-2'
    
    
    select 
      (
      select ItemId as id,
             ItemName as name
      from @T
      group by ItemId, ItemName
      for xml path('Item'), root('Items'), type
      ),
      (
      select ObjectId as id,
             ItemId as item_id,
             ObjectName as name
      from @T
      for xml path('Object'), root('Objects'), type
      )
    for xml path('root')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think i need a nudge in the right direction: I have two Tobjectlists
Need just a push in the right direction with this. I'm building a multi-language
I’m looking for a nudge in the right direction! I have a ColdFusion page
So I am in need of a little nudge or push in the right
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
This is homework, but I need a nudge. I can't find how to sort
I have a WML based source of data which I need to parse in
I have a double value d and would like a way to nudge it
I'm hoping you can point me in the right direction. I'm trying to generate

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.