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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:36:15+00:00 2026-06-06T02:36:15+00:00

i have the following codes in SQL XML . I need to insert a

  • 0

i have the following codes in SQL XML. I need to insert a parent element into a parent element in SQL XML.

i have the following table.

Firstname   Lastname    class   mark
John        Lim          V      60
Wills       smith        V      80
Mark        Bay          V      75
Carl        mark         V      65

and this is my SQL XML statements

 Select 
  Firstname,
  Lastname,
  class,
  mark
  from Student for xml path('Students'), type

The result as below

<Students>
  <Firstname>John</Firstname>
  <Lastname>Lim</Lastname>
  <class>V</class>
  <mark>60</mark>
</Students>
<Students>
  <Firstname>Wills</Firstname>
  <Lastname>smith</Lastname>
  <class>V</class>
  <mark>80</mark>
</Students>
<Students>
  <Firstname>Mark</Firstname>
  <Lastname>Bay</Lastname>
  <class>V</class>
  <mark>75</mark>
</Students>
<Students>
  <Firstname>Carl</Firstname>
  <Lastname>mark</Lastname>
  <class>V</class>
  <mark>65</mark>
</Students>

I want the below result were class and mark tag are enclosed in another tag:

    <Students>
  <Firstname>John</Firstname>
  <Lastname>Lim</Lastname>
  <Details>
    <class>V</class>
    <mark>60</mark>
  </Details>  
</Students>
<Students>
  <Firstname>Wills</Firstname>
  <Lastname>smith</Lastname>
  <Details>
    <class>V</class>
    <mark>80</mark>
  </Details>
</Students>
<Students>
  <Firstname>Mark</Firstname>
  <Lastname>Bay</Lastname>
  <Details>
    <class>V</class>
    <mark>75</mark>
  </Details>
</Students>
<Students>
  <Firstname>Carl</Firstname>
  <Lastname>mark</Lastname>
  <Details>
    <class>V</class>
    <mark>65</mark>
  </Details>
</Students>

Any idea how to go about doing this?

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-06-06T02:36:16+00:00Added an answer on June 6, 2026 at 2:36 am

    You can use a column alias.

    select Firstname,
           Lastname,
           class as "Details/class",
           mark as "Details/mark"
    from Student
    for xml path('Students'), type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to load a xml into a sql server table. The xml size
Hy i have the following code : import java.sql.*; import java.net.*; public class binsz
I have the following shortened classic ASP code that makes a SQL insert call...
I currently have the following block of SQL 2005 code. What I need to
I have the following Oracle PL/SQL codes that may be rusty from you guys
I have following tsql code in sql server 2008: declare @ID INT SET @ID
I have the following SQL code that runs against a Change Request database. Each
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have the following piece of SQL: select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) which comes through as
I have done the following modifications in my code: ConnectionPool.java: package com.dao; import java.sql.*;

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.